我为我糟糕的英语道歉。我的问题是,通向索引页面的路由不会首先进入控制器。我收到一个错误,告诉我图片变量未定义。这是我的路线代码:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
Route::get('/', 'HomeController@index');
Route::get('/home', 'HomeController@index');
Route::get('event', 'EventsController@index');
Route::get('video', 'VideosController@index');
Route::get('about', function() {
return view('about.about');
});
//Gallery routes
Route::get('gallery', 'PictureController@index');
Route::get('gallery/{picture}', 'PictureController@show');
Route::get('createPicture', 'PictureController@create');
Route::post('PictureStored', 'PictureController@store');
Route::delete('gallery/{picture}', 'PictureController@destroy');
Route::get('gallery/{picture}/edit', 'PictureController@edit');
Route::patch('gallery/{picture}', 'PictureController@update');
//Route::get('gallery/{picture}/comment/create', 'CommentsController@create');
Route::post('gallery/{picture}/comment', 'CommentsController@store')->name('comments.stored');
Route::delete('/comments/{comment}','CommentsController@destroy')->name('comments.destroyed');
//Route::resource('admin/comments','Admin\CommentsController');
//Videos routes
Route::get('video', 'VideosController@index');
Route::get('createVideo', 'VideosController@create');
Route::post('VideoStored', 'VideosController@store');
Auth::routes();
Route::get('/home', 'HomeController@index');
Route::get('admin/home', 'Admin\AdminController@index');
Route::get('admin', 'Admin\LoginController@showLoginForm');
Route::get('/admin-login', 'Admin\LoginController@showLoginForm')->name('admin.login');
Route::post('/admin-login', 'Admin\LoginController@login');
Route::post('/admin-password/email', 'Admin\ForgotPasswordController@sendResetLinkEmail ')->name('admin.password.email');
Route::get('admin-password/reset','Admin\ForgotPasswordController@showLinkRequestForm');
Route::post('admin-password/reset','Admin\ResetPasswordController@reset ');
Route::get('admin-password/reset/{token}','Admin\ResetPasswordController@showResetForm ');
//Events
Route::get('/event','EventsController@index');
Route::resource('admin/events','Admin\EventsController');
// Admin videos
Route::resource('admin/videos','Admin\VideosController');
//Admin Gallery
Route::resource('admin/pictures','Admin\PicturesController');
// Admin comment
Route::resource('admin/comments','Admin\CommentsController');
以防万一我会告诉你们我的HomeController:
public function index()
{
$pictures = Picture::orderBy('created_at','DESC')->paginate(3);
//Picture::latest()->get();
return view('home.home', compact("pictures"));
}
这是我对home.blade.php的看法:
<!-- Banner -->
<section id="banner">
<div class="inner">
<h1>Deanna Belton Art</h1>
</div>
</section>
<!-- gallery -->
<section id="galleries">
<!-- Photo Posts -->
<div class="gallery">
<header class="special">
<h2>Recent Posts</h2>
</header>
<div class="content">
<!--show the most recent posts-->
@foreach($pictures as $picture)
<div class="media {{$picture->tag }}">
<a href="{{"gallery/" . $picture->id}}" class="image">
<img class="pictures" src="./storage/app/{{$picture->picture}}" alt="" title="{{$picture->title}}" />
</a>
<h3 style="text-align: center;">{{$picture->title}}</h3>
</div>
@endforeach
</div>
<footer>
<a href="{{url('/gallery')}}" class="button big">All Pictures</a>
</footer>
</div>
</section>
</div>
提前致谢!
有人要求查看路线:列表。这是:
+--------+-----------+-------------------------------+----------------------+-------------------------------------------------------------------------+-----------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+-------------------------------+----------------------+-------------------------------------------------------------------------+-----------------+
| | GET|HEAD | / | | Closure | web |
| | POST | PictureStored | | App\Http\Controllers\PictureController@store | web |
| | POST | VideoStored | | App\Http\Controllers\VideosController@store | web |
| | GET|HEAD | about | | Closure | web |
| | GET|HEAD | admin | | App\Http\Controllers\Admin\LoginController@showLoginForm | web,guest:admin |
| | GET|HEAD | admin-login | admin.login | App\Http\Controllers\Admin\LoginController@showLoginForm | web,guest:admin |
| | POST | admin-login | | App\Http\Controllers\Admin\LoginController@login | web,guest:admin |
| | POST | admin-password/email | admin.password.email | App\Http\Controllers\Admin\ForgotPasswordController@sendResetLinkEmail | web,guest:admin |
| | POST | admin-password/reset | | App\Http\Controllers\Admin\ResetPasswordController@reset | web,guest:admin |
| | GET|HEAD | admin-password/reset | | App\Http\Controllers\Admin\ForgotPasswordController@showLinkRequestForm | web,guest:admin |
| | GET|HEAD | admin-password/reset/{token} | | App\Http\Controllers\Admin\ResetPasswordController@showResetForm | web,guest:admin |
| | POST | admin/comments | comments.store | App\Http\Controllers\Admin\CommentsController@store | web,auth:admin |
| | GET|HEAD | admin/comments | comments.index | App\Http\Controllers\Admin\CommentsController@index | web,auth:admin |
| | GET|HEAD | admin/comments/create | comments.create | App\Http\Controllers\Admin\CommentsController@create | web,auth:admin |
| | GET|HEAD | admin/comments/{comment} | comments.show | App\Http\Controllers\Admin\CommentsController@show | web,auth:admin |
| | DELETE | admin/comments/{comment} | comments.destroy | App\Http\Controllers\Admin\CommentsController@destroy | web,auth:admin |
| | PUT|PATCH | admin/comments/{comment} | comments.update | App\Http\Controllers\Admin\CommentsController@update | web,auth:admin |
| | GET|HEAD | admin/comments/{comment}/edit | comments.edit | App\Http\Controllers\Admin\CommentsController@edit | web,auth:admin |
| | GET|HEAD | admin/events | events.index | App\Http\Controllers\Admin\EventsController@index | web,auth:admin |
| | POST | admin/events | events.store | App\Http\Controllers\Admin\EventsController@store | web,auth:admin |
| | GET|HEAD | admin/events/create | events.create | App\Http\Controllers\Admin\EventsController@create | web,auth:admin |
| | DELETE | admin/events/{event} | events.destroy | App\Http\Controllers\Admin\EventsController@destroy | web,auth:admin |
| | PUT|PATCH | admin/events/{event} | events.update | App\Http\Controllers\Admin\EventsController@update | web,auth:admin |
| | GET|HEAD | admin/events/{event} | events.show | App\Http\Controllers\Admin\EventsController@show | web,auth:admin |
| | GET|HEAD | admin/events/{event}/edit | events.edit | App\Http\Controllers\Admin\EventsController@edit | web,auth:admin |
| | GET|HEAD | admin/home | | App\Http\Controllers\Admin\AdminController@index | web,auth:admin |
| | GET|HEAD | admin/pictures | pictures.index | App\Http\Controllers\Admin\PicturesController@index | web,auth:admin |
| | POST | admin/pictures | pictures.store | App\Http\Controllers\Admin\PicturesController@store | web,auth:admin |
| | GET|HEAD | admin/pictures/create | pictures.create | App\Http\Controllers\Admin\PicturesController@create | web,auth:admin |
| | DELETE | admin/pictures/{picture} | pictures.destroy | App\Http\Controllers\Admin\PicturesController@destroy | web,auth:admin |
| | PUT|PATCH | admin/pictures/{picture} | pictures.update | App\Http\Controllers\Admin\PicturesController@update | web,auth:admin |
| | GET|HEAD | admin/pictures/{picture} | pictures.show | App\Http\Controllers\Admin\PicturesController@show | web,auth:admin |
| | GET|HEAD | admin/pictures/{picture}/edit | pictures.edit | App\Http\Controllers\Admin\PicturesController@edit | web,auth:admin |
| | POST | admin/videos | videos.store | App\Http\Controllers\Admin\VideosController@store | web,auth:admin |
| | GET|HEAD | admin/videos | videos.index | App\Http\Controllers\Admin\VideosController@index | web,auth:admin |
| | GET|HEAD | admin/videos/create | videos.create | App\Http\Controllers\Admin\VideosController@create | web,auth:admin |
| | PUT|PATCH | admin/videos/{video} | videos.update | App\Http\Controllers\Admin\VideosController@update | web,auth:admin |
| | GET|HEAD | admin/videos/{video} | videos.show | App\Http\Controllers\Admin\VideosController@show | web,auth:admin |
| | DELETE | admin/videos/{video} | videos.destroy | App\Http\Controllers\Admin\VideosController@destroy | web,auth:admin |
| | GET|HEAD | admin/videos/{video}/edit | videos.edit | App\Http\Controllers\Admin\VideosController@edit | web,auth:admin |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | DELETE | comments/{comment} | comments.destroyed | App\Http\Controllers\CommentsController@destroy | web,auth:web |
| | GET|HEAD | createPicture | | App\Http\Controllers\PictureController@create | web |
| | GET|HEAD | createVideo | | App\Http\Controllers\VideosController@create | web |
| | GET|HEAD | event | | App\Http\Controllers\EventsController@index | web |
| | GET|HEAD | gallery | | App\Http\Controllers\PictureController@index | web |
| | DELETE | gallery/{picture} | | App\Http\Controllers\PictureController@destroy | web |
| | PATCH | gallery/{picture} | | App\Http\Controllers\PictureController@update | web |
| | GET|HEAD | gallery/{picture} | | App\Http\Controllers\PictureController@show | web |
| | POST | gallery/{picture}/comment | comments.stored | App\Http\Controllers\CommentsController@store | web,auth:web |
| | GET|HEAD | gallery/{picture}/edit | | App\Http\Controllers\PictureController@edit | web |
| | GET|HEAD | home | | App\Http\Controllers\HomeController@index | web |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest |
| | POST | logout | | App\Http\Controllers\Auth\LoginController@logout | web |
| | POST | password/email | | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\ResetPasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token} | | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest |
| | GET|HEAD | register | | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest |
| | GET|HEAD | video | | App\Http\Controllers\VideosController@index | web |
+--------+-----------+-------------------------------+----------------------+-------------------------------------------------------------------------+-----------------+
[chameleon@php laravelProject]$ php artisan route:list
+--------+-----------+-------------------------------+----------------------+-------------------------------------------------------------------------+-----------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+-------------------------------+----------------------+-------------------------------------------------------------------------+-----------------+
| | GET|HEAD | / | | Closure | web |
| | POST | PictureStored | | App\Http\Controllers\PictureController@store | web |
| | POST | VideoStored | | App\Http\Controllers\VideosController@store | web |
| | GET|HEAD | about | | Closure | web |
| | GET|HEAD | admin | | App\Http\Controllers\Admin\LoginController@showLoginForm | web,guest:admin |
| | GET|HEAD | admin-login | admin.login | App\Http\Controllers\Admin\LoginController@showLoginForm | web,guest:admin |
| | POST | admin-login | | App\Http\Controllers\Admin\LoginController@login | web,guest:admin |
| | POST | admin-password/email | admin.password.email | App\Http\Controllers\Admin\ForgotPasswordController@sendResetLinkEmail | web,guest:admin |
| | POST | admin-password/reset | | App\Http\Controllers\Admin\ResetPasswordController@reset | web,guest:admin |
| | GET|HEAD | admin-password/reset | | App\Http\Controllers\Admin\ForgotPasswordController@showLinkRequestForm | web,guest:admin |
| | GET|HEAD | admin-password/reset/{token} | | App\Http\Controllers\Admin\ResetPasswordController@showResetForm | web,guest:admin |
| | POST | admin/comments | comments.store | App\Http\Controllers\Admin\CommentsController@store | web,auth:admin |
| | GET|HEAD | admin/comments | comments.index | App\Http\Controllers\Admin\CommentsController@index | web,auth:admin |
| | GET|HEAD | admin/comments/create | comments.create | App\Http\Controllers\Admin\CommentsController@create | web,auth:admin |
| | GET|HEAD | admin/comments/{comment} | comments.show | App\Http\Controllers\Admin\CommentsController@show | web,auth:admin |
| | DELETE | admin/comments/{comment} | comments.destroy | App\Http\Controllers\Admin\CommentsController@destroy | web,auth:admin |
| | PUT|PATCH | admin/comments/{comment} | comments.update | App\Http\Controllers\Admin\CommentsController@update | web,auth:admin |
| | GET|HEAD | admin/comments/{comment}/edit | comments.edit | App\Http\Controllers\Admin\CommentsController@edit | web,auth:admin |
| | GET|HEAD | admin/events | events.index | App\Http\Controllers\Admin\EventsController@index | web,auth:admin |
| | POST | admin/events | events.store | App\Http\Controllers\Admin\EventsController@store | web,auth:admin |
| | GET|HEAD | admin/events/create | events.create | App\Http\Controllers\Admin\EventsController@create | web,auth:admin |
| | DELETE | admin/events/{event} | events.destroy | App\Http\Controllers\Admin\EventsController@destroy | web,auth:admin |
| | PUT|PATCH | admin/events/{event} | events.update | App\Http\Controllers\Admin\EventsController@update | web,auth:admin |
| | GET|HEAD | admin/events/{event} | events.show | App\Http\Controllers\Admin\EventsController@show | web,auth:admin |
| | GET|HEAD | admin/events/{event}/edit | events.edit | App\Http\Controllers\Admin\EventsController@edit | web,auth:admin |
| | GET|HEAD | admin/home | | App\Http\Controllers\Admin\AdminController@index | web,auth:admin |
| | GET|HEAD | admin/pictures | pictures.index | App\Http\Controllers\Admin\PicturesController@index | web,auth:admin |
| | POST | admin/pictures | pictures.store | App\Http\Controllers\Admin\PicturesController@store | web,auth:admin |
| | GET|HEAD | admin/pictures/create | pictures.create | App\Http\Controllers\Admin\PicturesController@create | web,auth:admin |
| | DELETE | admin/pictures/{picture} | pictures.destroy | App\Http\Controllers\Admin\PicturesController@destroy | web,auth:admin |
| | PUT|PATCH | admin/pictures/{picture} | pictures.update | App\Http\Controllers\Admin\PicturesController@update | web,auth:admin |
| | GET|HEAD | admin/pictures/{picture} | pictures.show | App\Http\Controllers\Admin\PicturesController@show | web,auth:admin |
| | GET|HEAD | admin/pictures/{picture}/edit | pictures.edit | App\Http\Controllers\Admin\PicturesController@edit | web,auth:admin |
| | POST | admin/videos | videos.store | App\Http\Controllers\Admin\VideosController@store | web,auth:admin |
| | GET|HEAD | admin/videos | videos.index | App\Http\Controllers\Admin\VideosController@index | web,auth:admin |
| | GET|HEAD | admin/videos/create | videos.create | App\Http\Controllers\Admin\VideosController@create | web,auth:admin |
| | PUT|PATCH | admin/videos/{video} | videos.update | App\Http\Controllers\Admin\VideosController@update | web,auth:admin |
| | GET|HEAD | admin/videos/{video} | videos.show | App\Http\Controllers\Admin\VideosController@show | web,auth:admin |
| | DELETE | admin/videos/{video} | videos.destroy | App\Http\Controllers\Admin\VideosController@destroy | web,auth:admin |
| | GET|HEAD | admin/videos/{video}/edit | videos.edit | App\Http\Controllers\Admin\VideosController@edit | web,auth:admin |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | DELETE | comments/{comment} | comments.destroyed | App\Http\Controllers\CommentsController@destroy | web,auth:web |
| | GET|HEAD | createPicture | | App\Http\Controllers\PictureController@create | web |
| | GET|HEAD | createVideo | | App\Http\Controllers\VideosController@create | web |
| | GET|HEAD | event | | App\Http\Controllers\EventsController@index | web |
| | GET|HEAD | gallery | | App\Http\Controllers\PictureController@index | web |
| | DELETE | gallery/{picture} | | App\Http\Controllers\PictureController@destroy | web |
| | PATCH | gallery/{picture} | | App\Http\Controllers\PictureController@update | web |
| | GET|HEAD | gallery/{picture} | | App\Http\Controllers\PictureController@show | web |
| | POST | gallery/{picture}/comment | comments.stored | App\Http\Controllers\CommentsController@store | web,auth:web |
| | GET|HEAD | gallery/{picture}/edit | | App\Http\Controllers\PictureController@edit | web |
| | GET|HEAD | home | | App\Http\Controllers\HomeController@index | web |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest |
| | POST | logout | | App\Http\Controllers\Auth\LoginController@logout | web |
| | POST | password/email | | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\ResetPasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token} | | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest |
| | GET|HEAD | register | | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest |
| | GET|HEAD | video | | App\Http\Controllers\VideosController@index | web |
+--------+-----------+-------------------------------+----------------------+-------------------------------------------------------------------------+-----------------+
答案 0 :(得分:0)
PHPStorm由于某种原因没有上传..... 我讨厌PHPStorm及其故障。