-1

I am working on a Laravel Project and I need some help

I am passing data from AdsController.php

$ads = Ads::all(); 
return view('Ads/index', enter code herecompact('ads','users'));

But in the Same view I want to get data from other tables

@foreach ($ads as $ad) 
$ad->id // Now from this Id I want to get the user's name and picture so..
{{AdsControlller::get_user_img($ad->id)}}
@endforeach

in The AdsController I have the function

Public static function get_user_img($id){
$user = User::find($id);
return $user-img;
}

But I keep getting this error Class 'AdsController' not Found !

Ali Veseli
  • 53
  • 2
  • 5
  • Inject all the data that your view needs in your AdsController. But most of all, read the documentation and experiment with the examples first. https://laravel.com/docs/5.6 – Tom Apr 10 '18 at 11:17

1 Answers1

1

You can reference the class by its fully qualified name, including namespaces. If AdsController is in App\Http\Controllers (might be different for you), then:

{{\App\Http\Controllers\AdsController::get_user_img($ad->id)}}

(The leading slash indicates to start at the global namespace.)

Aurel Bílý
  • 7,068
  • 1
  • 21
  • 34