lundi 4 décembre 2017

how to preent undefined property when only one record found in Laravel

I was try to make a search function so i'm doing like this:

public function search(Request $request)
    {
       $query = $request->query('q');

       $posts = DB::table('posts')->where('title', 'LIKE',  '%'.$query.'%')->get();

       return view('admin.dashboard.search')->with('users',$users)->with('posts',$posts);
    }

but when i try to fetch the result i got some errors like this:

"Undefined property: stdClass::$user (View: E:\laragon\www\blog\resources\views\admin\dashboard\search.blade.php)"

it was errors in this line:

<td><?php echo e($post->user->name); ?></td>

so how can i fix it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire