Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.2未定义的变量主题_Php_Laravel_Laravel 5.2 - Fatal编程技术网

Php Laravel 5.2未定义的变量主题

Php Laravel 5.2未定义的变量主题,php,laravel,laravel-5.2,Php,Laravel,Laravel 5.2,我正在制作一个论坛,如果用户点击一个主题,他会被重定向到所有属于该主题的主题所在的页面。我想做的是,用户能够点击主题并重定向到它 问题是,我得到一个错误,说未定义变量:theme 正如您在下面的代码中所看到的,我在theme.blade.php中有一个foreach循环,它循环属于他/她单击的主题的所有主题。在循环的开头有一个我不知道你是否可以使用double'->with'选项 以下是有效的方法: return view('topics/topic', ['topics' => $top

我正在制作一个论坛,如果用户点击一个主题,他会被重定向到所有属于该主题的主题所在的页面。我想做的是,用户能够点击主题并重定向到它

问题是,我得到一个错误,说
未定义变量:theme


正如您在下面的代码中所看到的,我在
theme.blade.php
中有一个foreach循环,它循环属于他/她单击的主题的所有主题。在循环的开头有一个
我不知道你是否可以使用double'->with'选项

以下是有效的方法:

return view('topics/topic', ['topics' => $topics, 'theme'=> $theme]);
传递数组作为视图的第二个参数。您可以添加任意数量的键和变量

Route::get('/', 'ThemesController@index')->name('home');
Route::get('/theme/{theme_id}/topics', 'ThemesController@show')->name('showtheme');


Route::get('/theme/{theme_id}/topics/{topic_id}', 'TopicsController@topic')->name('showtopic');


Route::group(['middleware' => 'App\Http\Middleware\AdminMiddleware'], function() {

//THEMES

Route::get('/theme/{theme_id}/edit', 'ThemesController@edit')->name('edittheme');
Route::patch('/theme/{theme_id}/edit', 'ThemesController@update')->name('updatetheme');

Route::get('/theme/create', 'ThemesController@create')->name('createtheme');
Route::post('/theme/create', 'ThemesController@save')->name('savetheme');

Route::delete('/theme/{theme_id}/delete', 'ThemesController@destroy')->name('deletetheme');

//TOPICS

Route::get('/theme/{theme_id}/topics/{topic_id}/edit', 'TopicsController@edit')->name('edittopic');
Route::patch('/theme/{theme_id}/topics/{topic_id}/edit', 'TopicsController@update')->name('updatetopic');

Route::get('/theme/{theme_id}/topics/create', 'TopicsController@create')->name('createtopic');
Route::post('/theme/{theme_id}/topics/create', 'TopicsController@save')->name('savetopic');

Route::delete('/theme/{theme_id}/topics/{topic_id}/delete', 'TopicsController@destroy')->name('deletetopic');

});

Route::get('user/profile', 'UserController@profile')->name('showprofile');
Route::post('user/profile', 'UserController@update_avatar');
public function show($id)
{
    $theme = Theme::find($id);
    $topics = Topic::find($id);

    return view('topics/topic')->with('topics', $topics)->with('theme', $theme);
}
return view('topics/topic', ['topics' => $topics, 'theme'=> $theme]);