It seems fine to me.
Can you show us the full error message to get the idea in which file you are getting this error?
Hi! I have this error in Laravel 6. I am new to Laravel..I actually started a few days ago and I want to edit some user posts and I get this error. Here is my code form index.blade.php
@extends('layouts.admin')
@section('content')
@if(Session::has('info'))
<div class="row">
<div class="col-md-12">
<p class="alert alert-info">{{ Session::get('info') }}</p>
</div>
</div>
@endif
<div class="row">
<div class="col-md-12">
<a href="{{ route('admin.create') }}" class="btn btn-success">New Post</a>
</div>
</div>
<hr>
<div class="row">
<div class="col-md-12">
<p><strong>Learning Laravel</strong> <a href="{{ route('admin.edit', ['id' => 1]) }}">Edit</a></p>
</div>
</div>
@endsection
Here is my code from web.php
<?php
Route::get('/', function () {
return view('blog.index');
})->name('blog.index');
Route::get('post/{id}', function ($id) {
if($id==1){
$post =[
'title' => 'Learning Laravel',
'content' => 'This blog post will get you right on track with Laravel'
];
}else{
$post =[
'title' => 'Something else',
'content' => 'Some other content'
];
}
return view('blog.post', ['post' => $post]);
})->name('blog.post');
Route::get('about', function () {
return view('other.about');
})->name('other.about');
// here i grouped all the routes with the admin name
// so that if i want to change all the routes with the admin name
//i simple change the prefix, which won't ;ead to any errors
Route::group(['prefix' => 'admin'], function() {
Route::get('', function () {
return view('admin.index');
})->name('admin.index');
Route::get('create', function () {
return view('admin.create');
})->name('admin.create');
//Dependency injection for post request
Route::post('create', function(Illuminate\Http\Request $request) {
return "It works!";
})->name('admin.create');
Route::get('edit/{id}', function ($id) {
if($id==1){
$post =[
'title' => 'Learning Laravel',
'content' => 'This blog post will get you right on track with Laravel'
];
}else{
$post =[
'title' => 'Something else',
'content' => 'Some other content'
];
}
return view('admin.edit', ['post' => $post]);
})->name('admin.edit');
//Dependency injection for post request
Route::post('edit', function(Illuminate\Http\Request $request) {
return redirect()
->route('admin.edit')
->with ('info', 'Post edited. New title ' . $request -> input('title'));
})->name('admin.update');
});
Thnak you ! :)
I think you have to do this
return view('admin.edit',compact('post','id');
Please or to participate in this conversation.