Я уже пробовал несколько вещей, но по какой-то причине в моей установке Homestead Laravel 6.17 У меня есть один маршрут / search, который дает 404. Я ожидаю, что он будет перенаправлен, если пользователь ничего не вводит в поле поиска.
Я выполнил команду route: list и получил это
vagrant@homestead:~/www/nettubenew$ php artisan route:list
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+------------+
| | GET|HEAD | / | home | App\Http\Controllers\GuestController@index | web |
| | GET|HEAD | channel/{channel} | | App\Http\Controllers\ChannelController@index | web |
| | PUT | channel/{channel}/edit | | App\Http\Controllers\ChannelSettingsController@update | web,auth |
| | GET|HEAD | channel/{channel}/edit | | App\Http\Controllers\ChannelSettingsController@edit | web,auth |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web |
| | GET|HEAD | password/confirm | password.confirm | App\Http\Controllers\Auth\ConfirmPasswordController@showConfirmForm | web,auth |
| | POST | password/confirm | | App\Http\Controllers\Auth\ConfirmPasswordController@confirm | web,auth |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web |
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController@reset | web |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web |
| | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest |
| | GET|HEAD | search | search | App\Http\Controllers\SearchController@index | web |
| | GET|HEAD | upload | | App\Http\Controllers\VideoUploadController@index | web,auth |
| | POST | video | | App\Http\Controllers\VideoController@store | web,auth |
| | GET|HEAD | {channel} | | App\Http\Controllers\ChannelController@index | web |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+------------+
Мой веб. php
Route::get('/','HomeController@index')->name('home');
Route::get('/','GuestController@index')->name('home');
Auth::routes();
// Route::get('/home', 'HomeController@index')->name('home');
Route::group(['middleware' => ['auth']], function(){
Route::get('/upload','VideoUploadController@index');
Route::post('/video','VideoController@store');
Route::get('/channel/{channel}/edit','ChannelSettingsController@edit');
Route::put('/channel/{channel}/edit','ChannelSettingsController@update');
});
Route::get('/channel/{channel}','ChannelController@index');
Route::get('/{channel}','ChannelController@index');
Route::get('/search','SearchController@index')->name('search');
SearchController. php
<?php
namespace App\Http\Controllers;
use App\Models\Channel;
use App\Http\Requests;
use Illuminate\Http\Request;
class SearchController extends Controller
{
public function index(Request $request)
{
if(!$request->q){
return redirect('/');
}
$channels = Channel::search($request->q)->take(2)->get();
return view('search.index', [
'channels' => $channels
]);
}
}
index.blade. php в моем поиске
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Search for "{{ Request::get('q') }}"</div>
<div class="card-body">
@if ($channels->count())
<h4>Channels</h4>
<div class="well">
@foreach ($channels as $channel)
<div class="media">
<div class="media-left">
<a href="/channel/{{ $channel->slug }}">
<img src="{{ $channel->getImage }}" alt="{{ $channel->name }} image" class="media-object">
</a>
</div>
<div class="media-body">
<a href="/channel/{{ $channel->slug }}" class="media-heading">{{ $channel->name }}</a>
Subscription count
</div>
</div>
@endforeach
</div>
@endif
</div>
</div>
</div>
</div>
</div>
@endsection