I have my flask app and I am able to query the database in a view named 'blog.blade.php', but now to I want to transfer my control from this view to another view called 'viewblog.blade.php' and now I want to query the database in this view using url parameters that I am sending form first view. My problem is, I am getting an error in viewblog.php file.
blog.blade.php
@foreach($blogs as $blog)
<div class="col-md-6" style="padding: 25px;">
<div class="card" style="border: 0;">
<div class="card-body">
<h3 class="card-title"><a href="viewblog?blog_id=" target="_blank"></a></h3>
<p></p>
<a href="viewblog?blog_id=" class="btn btn-outline-danger" target="_blank">Continue reading...</a>
</div>
</div>
</div>
@endforeach
</div>
viewblog.blade.php
<div class="row" style="padding: 20px;">
</div>
BlogController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Blog;
class BlogController extends Controller
{
function getBlogs(){
$blogs = Blog::All();
return view("blogs",['blogs'=>$blogs]);
}
function viewBlog(Request $req){
$bid = $req->blog_id;
$blogs = Blog::select('select * from blogs where id = ' . $bid);
return view("viewblog",['blogs'=>$blogs]);
}
}
Blog.php (Blog modal)
namespace App;
use Illuminate\Database\Eloquent\Model;
class Blog extends Model
{
//
}
source https://stackoverflow.com/questions/69293552/how-to-query-database-in-flask-app-using-url-parameters
Comments
Post a Comment