2 models multiple loop
I have 2 declarations of my 2 models in my controller
*namespace App\Http\Controllers; use App\Http\Requests; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Routing\UrlGenerator; use App\mot_users; use App\branch; class mot extends Controller {
protected $url;
public function __construct(UrlGenerator $url)
{
$this->middleware('auth');
$this->url = $url;
}
//replace dashes with spaces functions
private function replace_dashes($string) {
return str_replace("-", " ", $string);
}
//index page, dashboard page
public function index()
{
$data = branch::all();
$breadcrumbs = '<li class="active"><a href="' . $this->url->to('/') . '">Dashboard</a></li>';
$showpagefilter = "yes";
return view('pages.home', compact('breadcrumbs', 'showpagefilter', 'data'));
}*
and I display data with foreach in blade way
- @foreach($data as $data)
- {{ $data->name }} @endforeach
everything works fine, except if I declare multipe foreach, an error occurred saying
ErrorException in a0910ce17cd3f20917c51c28f39f2fa5 line 461: Trying to get property of non-object (View: C:\wamp\www\laravel\resources\views\master.blade.php) (View: C:\wamp\www\laravel\resources\views\master.blade.php)
and the line 461 is the 2nd declaration of the foreach.
any ideas whats wrong?
any help, clues, ideas, suggestions, recommendations is greatly appreciated. Thank you!
Please or to participate in this conversation.