public function getIndex() { // Get all the blog posts /*$posts = Post::with(array( 'author' => function($query) { $query->withTrashed(); }, ))->orderBy('created_at', 'DESC')->paginate(10);*/ $posts =Post::with(array('search' => function($query) { $query->where('title', 'like', '%Lorem ipsum%')->withTrashed(); }))->orderBy('created_at', 'DESC')->paginate(10); // Show the page return View::make('frontend/blog/index', compact('posts')); }
This is my code in the controller. I am using the starter kit available on GitHub.
I created this model for this controller
public function search() { return $this->belongsTo('Post', 'user_id'); }
The problem is not that the results in which the title contains "Lorem ipsum" are not accepted. It just prints all the values ββfrom the table.
How can I implement this to get only those values ββthat contain my tag / keyword. I am doing this to add a search parameter to the laravel site
source share