У меня проблема с "404 | Не найдено". Маршрут существует, но у меня все еще есть проблема.
Я уже пробовал с:
php artisan route:list
и маршрут действительно существует.
web.php:
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/p/create', 'PostsController@create');
Route::get('/p/{post}', 'PostsController@show');
Route::post('/p', 'PostsController@store');
Route::get('/profile/{user}', 'ProfilesController@index')->name('profile.show');
Route::get('/profile/{user}/edit', 'ProfilesController@edit')->name('profile.edit'); //this shows the form of edit profile
Route::patch('/profile/{user}', 'ProfilesController@update')->name('profile.update'); //this will actually do the process of updating our profile
ProfilesController.php:
public function edit(User $user)
{
return view('profiles.edit', compact('user'));
}
public function update(User $user){ //some validation
$data =request()->validate([
'title' => 'required',
'description' => 'required',
'url' => 'url', //require the http://
'image' => '',
]);
auth()->user()->profile->update($data); //auth() is a protection. Without this, an external user, for example in incognite, can edit the profile
}
edit.blade.php:
@extends('layouts.app')
@section('content')
<div class="container">
<form action="/profile->{{ $user->id }}" enctype="multipart/form-data" method="POST">
@csrf
@method('PATCH') <!--it's not permitted write method = 'patch', by default it will be get-->
<div class="row">
<div class="col-8 offset-2">
<div class="row">
<h2>Edit Profile</h2>
</div>
<div class="form-group row">
<label for="title" class="col-md-4 col-form-label">Title</label>
<input id="title"
type="text"
class="form-control @error('title') is-invalid @enderror"
name="title"
value="{{ old('title') ?? $user->profile->title }}"
autocomplete="title" autofocus>
@error('title')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
index.blade.php:
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-3 p-5">
<img src="https://scontent-fco1-1.cdninstagram.com/vp/1ba68a1705bb9cdd1f7f2ea9ea062810/5D79BFC8/t51.2885-19/s320x320/22709172_932712323559405_7810049005848625152_n.jpg?_nc_ht=scontent-fco1-1.cdninstagram.com" style = "height:150px" class = "rounded-circle">
</div>
<div class="col-9 pt-5">
<div class="d-flex justify-content-between align-items-baseline">
<h1>{{ $user -> username}}</h1>
<a href="/p/create">Add New Post</a>
</div>
<a href="/profile/{{ $user->id }}/edit">Edit Profile</a>
<div class = "d-flex">
<div class = "pr-5"><strong>{{ $user->posts->count() }}</strong> posts</div>
<div class = "pr-5"><strong>23k</strong> followers</div>
<div class = "pr-5"><strong>212</strong> following</div>
</div>
<div class = "pt-4 font-weight-bold">{{ $user->profile->title }}</div>
<div>{{ $user->profile->description }}</div>
<div><a href="#">{{ $user->profile->url }}</a></div>
</div>
</div>
<div class="row pt-5">
@foreach($user->posts as $post)
<div class="col-4 pb-4">
<a href="/p/{{ $post->id }}">
<img src="/storage/{{ $post->image }}" class = "w-100">
</a>
</div>
@endforeach
</div>
</div>
@endsection
Ошибка только «404 | Not Found». Когда я нажимаю кнопку для редактирования, адрес становится: «http://localhost:8000/profile->1", и ошибка, вероятно, там.