ErrorException(E_ERROR) 从空值创建默认对象(查看:D:\ Michael .. \ resources \ views \ home.blade.php)
这是我的路线
Route::get('/', function () {
return view('auth.login');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/home/{team_id}', 'HomeController@materialID');
这是我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Team;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$code = \App\Team::where('team_name',"Coding")->get();
$design = \App\Team::where('team_name',"Design")->get();
$qa = \App\Team::where('team_name',"Quality Assurance")->get();
$ana = \App\Team::where('team_name',"Analytics")->get();
return view('home',compact('code','design','qa','ana'));
}
public function materialID($team_id)
{
$material = Team::find($team_id);
return view('material', compact('material'));
}
}
这就是我在我的刀片中称呼它的方式
<a href="{{ url('home',$material->team_id = '1')}}">
<h3>{{$code[0]->team_name}}</h3>
<p style="padding-right: 35px">{{$code[0]->team_description}}</p>
</a>
我不知道如何解决它。
答案 0 :(得分:0)
你应该试试这个:
<a href="{{ url('home','1')}}">
<h3>{{$code[0]->team_name}}</h3>
<p style="padding-right: 35px">{{$code[0]->team_description}}</p>
</a>
答案 1 :(得分:0)
将团队ID作为参数传递给网址:
<a href="{{ url('home',['team_id'=>$material->team_id])}}">
</a>