Missing required parameter for [Route: BatterFirst.update] [URI: BatterFirst/{BatterFirst}] [Missing parameter: BatterFirst]. edit.blade.php) - laravel

While I am doing laravel CRUD project I got . I stuck here its 2 days
Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameter for [Route: BatterFirst.update] [URI: BatterFirst/{BatterFirst}] [Missing parameter: BatterFirst]. (View: C:\xampp\htdocs\CricBangla\resources\views\BatterFirst\edit.blade.php) Error.
I can`t find whire is the error.
Here is my web.php
Route::resource('BatterFirst', BatterFirstController::class);
This is my model BatterFirst.php
class BatterFirst extends Model
{
use HasFactory;
protected $table = 'batterfirst';
protected $fillable = [
'name', 'runs', 'balls', 'sixs', 'fours'
];
}
This is my BatterFirstController.php
<?php
namespace App\Http\Controllers;
use App\Models\BatterFirst;
use Illuminate\Http\Request;
class BatterFirstController extends Controller
{
public function index()
{
$data = BatterFirst::latest()->paginate(5);
return view('BatterFirst.index',compact('data'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
public function create()
{
return view('BatterFirst.create');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'runs' => 'required',
'balls' => 'required',
'sixs' => 'required',
'fours' => 'required',
]);
BatterFirst::create($request->all());
return redirect()->route('BatterFirst.index')
->with('success','Batter created successfully.');
}
public function show(BatterFirst $batterFirst)
{
return view('BatterFirst.show',compact('batterFirst'));
}
public function edit(BatterFirst $batterFirst)
{
return view('BatterFirst.edit',compact('batterFirst'));
}
public function update(Request $request, BatterFirst $batterFirst)
{
$request->validate([
'name' => 'required',
'runs' => 'required',
'balls' => 'required',
'sixs' => 'required',
'fours' => 'required',
]);
$batterFirst->update($request->all());
return redirect()->route('BatterFirst.index')
->with('success','Batter updated successfully');
}
public function destroy(BatterFirst $batterFirst)
{
$batterFirst->delete();
return redirect()->route('BatterFirst.index')
->with('success','Batter deleted successfully');
}
}
This is my edit.blade.php
#extends('BatterFirst.layout')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Edit Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('BatterFirst.index') }}"> Back</a>
</div>
</div>
</div>
#if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form action="{{ route('BatterFirst.update',$batterFirst->id) }}" method="POST">
#csrf
#method('PUT')
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" value="{{ $batterFirst->name }}" class="form-control" placeholder="name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Runs:</strong>
<input type="number" name="runs" value="{{ $batterFirst->runs }}" class="form-control" placeholder="runs"> </div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Balls:</strong>
<input type="number" name="balls" value="{{ $batterFirst->balls }}" class="form-control" placeholder="balls"> </div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Sixs:</strong>
<input type="number" name="sixs" value="{{ $batterFirst->runs }}" class="form-control" placeholder="sixs"> </div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Fours:</strong>
<input type="number" name="fours" value="{{ $batterFirst->fours }}" class="form-control" placeholder="fours"> </div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
#endsection
In this image when i click delete button it showing Batter delete successfully but not deleting Batter
This is my index.blade.php
#extends('BatterFirst.layout')
#section('content')
<div class="row" style="margin-top: 5rem;">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel 8 CRUD Example from scratch - laravelcode.com</h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('BatterFirst.create') }}"> Create New Post</a>
</div>
</div>
</div>
#if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
#endif
<table class="table table-bordered">
<tr>
<th>No</th>
<th>Name</th>
<th>Runs</th>
<th>Balls</th>
<th>Sixs</th>
<th>Fours</th>
<th>Strick Rate</th>
</tr>
#foreach ($data as $key => $value)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $value->name }}</td>
<td>{{ $value->runs }}</td>
<td>{{ $value->balls }}</td>
<td>{{ $value->sixs }}</td>
<td>{{ $value->fours }}</td>
{{-- <td>{{ $value->runs/$value->balls*100 }}</td> --}}
<td>#if ($value->runs > 0 and $value->runs ==0)
{{ $value->runs*100 }}
#elseif ($value->balls>0 and $value->runs ==0)
{{ $value->balls*$value->runs }}
#elseif ($value->balls==0 and $value->runs ==0)
{{ $value->balls * $value->runs }}
#elseif ($value->runs>0 and $value->balls>=0)
{{ $value->runs/$value->balls*100 }}
#endif
</td>
<td>
<form action="{{ route('BatterFirst.destroy',$value->id) }}" method="POST">
<a class="btn btn-info" href="{{ route('BatterFirst.show',$value->id) }}">Show</a>
<a class="btn btn-primary" href="{{ route('BatterFirst.edit',$value->id) }}">Edit</a>
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
#endforeach
</table>
{!! $data->links() !!}
#endsection
Note: I just started learning laravel. Thanks

Try to delete the method POST. Update will use PUT as Method.
<form action="{{ route('BatterFirst.update',$batterFirst->id) }}" method="POST">
#csrf
#method('PUT')
and then change inside your route function this. Pass the id inside a array.
"{{route('BatterFirst.update',['id' => $batterFirst->id])}}"
then will ĺooking so:
<form action="{{ route('BatterFirst.update',['id' => $batterFirst->id]) }}" method="PUT">
#csrf
#method('PUT')

It happens CZ of wrong naming of table and model, folders

Related

Missing required parameter for [Route: rolespermissions.update] [URI: rolespermissions/{rolespermission}] [Missing parameter: rolespermission]

Why am I getting the following error message:
Missing required parameter for [Route: rolespermissions.update] [URI:
rolespermissions/{rolespermission}] [Missing parameter:
rolespermission]. (View:
C:\laragon\www\idoc4\resources\views\rolespermissions\edit.blade.php)
The code for my controller is as follows:
public function edit(Role $role)
{
$permissions = Permission::all();
// return view('rolespermissions.edit',compact('role', 'permissions'));
return view('rolespermissions.edit',[ 'role' => $role, 'permisssions' => $permissions]);
}
My blade code is as follows:
#extends('layouts.app')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2></h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('rolespermissions.index') }}"> Back</a>
</div>
</div>
</div>
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form action="{{ route('rolespermissions.update',$role->id) }}" method="POST" enctype="multipart/form-data">
#csrf
#method('PUT')
<div class="card card-primary m-1" >
<div class="card-header">
Kemaskini Peranan Kebenaran
</div>
<div class="row">
{{ $role->name }}
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
#foreach ($permissions as $permission)
<input type="checkbox" name="permission[]" value="{{$permission->id}}" />{{$permission->name}}<br />
#endforeach
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</form>
#endsection
Appreciate your help. Thank you.
I rewrote the controller as follows: Correct it was sending null before this
public function edit($id)
{
$role = Role::find($id);
// dd($role);
$permissions = Permission::all();
// return view('rolespermissions.edit',compact('role', 'permissions'));
return view('rolespermissions.edit',[ 'role' => $role, 'permissions' => $permissions]);
}

Missing required parameter laravel-8

I got error Missing required parameter for [Route: battersecondinnings.update] [URI: battersecondinnings/{battersecondinning}] [Missing parameter: battersecondinning]. (View: C:\xampp\htdocs\ContentBaseApp - 1.0.2\resources\views\battersecondinnings\edit.blade.php)
This is my C:\xampp\htdocs\ContentBaseApp - 1.0.2\resources\views\battersecondinnings\edit.blade.php
#extends('layouts.app')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Edit Batter</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('battersecondinnings.index') }}"> Back</a>
</div>
</div>
</div>
#if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form action="{{ route('battersecondinnings.update', $battersecondinnings->id) }}" method="POST" enctype="multipart/form-data">
#csrf
#method('PUT')
<div class="row">
<div class="form-group row">
<div class="col-md-6">
<strong>ব্যাটসম্যান:</strong>
<input type="text" name="name" value="{{ $battersecondinnings->name }}" class="form-control" placeholder="ব্যাটসম্যান">
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<strong>রান:</strong>
<input type="number" name="runs" value="{{ $battersecondinnings->runs }}" class="form-control" placeholder="রান">
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<strong>বল:</strong>
<input type="number" name="balls" value="{{ $battersecondinnings->balls }}" class="form-control" placeholder="বল">
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<strong>ছক্কা:</strong>
<input type="number" name="sixs" value="{{ $battersecondinnings->sixs }}" class="form-control" placeholder="ছক্কা">
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<strong>চার:</strong>
<input type="number" name="fours" value="{{ $battersecondinnings->fours }}" class="form-control" placeholder="চার">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
#endsection
This is my BattersecondiningsController.php
public function edit(Battersecondinnings $battersecondinnings)
{
return view('battersecondinnings.edit',compact('battersecondinnings'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param \App\Models\Battersecondinnings $battersecondinnings
* #return \Illuminate\Http\Response
*/
public function update(Request $request, Battersecondinnings $battersecondinnings)
{
$request->validate([
'name' => 'required',
'runs' => 'required',
'balls' => 'required',
'sixs' => 'required',
'fours' => 'required',
]);
$battersecondinnings->update($request->all());
return redirect()->route('battersecondinnings.index')
->with('success','Batter second innings updated successfully');
}
But same things is working in products/edit.blade.php
<form action="{{ route('products.update', $product->id) }}" method="POST" enctype="multipart/form-data">
#csrf
#method('PUT')
This is ProductController.php
public function edit(Product $product)
{
return view('products.edit',compact('product'));
}
public function update(Request $request, Product $product)
{
$request->validate([
'name' => 'required',
'runs' => 'required',
'balls' => 'required',
'sixs' => 'required',
'fours' => 'required',
]);
$product->update($request->all());
return redirect()->route('products.index')
->with('success','Product updated successfully');
}
This is web.php
Route::resource('battersecondinnings', BattersecondinningsController::class);
In the Route 'battersecondinnings.update' what is missing is enctype="multipart/form-data". Add it and try again.
Please ckeck this answer in stackoverflow multipart/form-data meaning

Base table or view not found: 1146 Table 'cricbangla.batter_firsts' doesn't exist (SQL: select count(*) as aggregate from `batter_firsts`)-Laravel-8

This is my database name in .env
DB_DATABASE=cricbangla
This is a screenshot of my database and all table
This is The Image of my database
You can see there is no table called batter_firsts and i don't want any table with this name
I am doing a CRUD project in laravel-8 where i create a table name batterfirst.php
Schema::create('batterfirst', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('runs');
$table->integer('balls');
$table->integer('sixs');
$table->integer('fours');
$table->timestamps();
});
Where my web.php is
<?php
use App\Http\Controllers\BatterFirstController;
Route::get('/', function () {
return view('welcome');
});
Route::resource('BatterFirst', BatterFirstController::class);
Where my model name is BatterFirst.php which is
class BatterFirst extends Model
{
use HasFactory;
protected $fillable = [
'name', 'runs', 'balls', 'sixs', 'fours'
];
}
And My Controller is BatterFirstController.php which is
<?php
namespace App\Http\Controllers;
use App\Models\BatterFirst;
use Illuminate\Http\Request;
class BatterFirstController extends Controller
{
public function index()
{
$data = BatterFirst::latest()->paginate(5);
return view('BatterFirst.index',compact('data'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
public function create()
{
return view('BatterFirst.create');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'runs' => 'required',
'balls' => 'required',
'sixs' => 'required',
'fours' => 'required',
]);
BatterFirst::create($request->all());
return redirect()->route('BatterFirst.index')
->with('success','Batter created successfully.');
}
public function show(BatterFirst $batterFirst)
{
return view('BatterFirst.show',compact('batterfirst'));
}
public function edit(BatterFirst $batterFirst)
{
return view('BatterFirst.edit',compact('batterfirst'));
}
public function update(Request $request, BatterFirst $batterFirst)
{
$request->validate([
'name' => 'required',
'runs' => 'required',
'balls' => 'required',
'sixs' => 'required',
'fours' => 'required',
]);
$batterFirst->update($request->all());
return redirect()->route('BatterFirst.index')
->with('success','Batter updated successfully');
}
public function destroy(BatterFirst $batterFirst)
{
$batterFirst->delete();
return redirect()->route('BatterFirst.index')
->with('success','Batter deleted successfully');
}
}
This is my index.php file inside BatterFirst Folder BatterFirst/index.blade.php
#extends('BatterFirst.layout')
#section('content')
<div class="row" style="margin-top: 5rem;">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel 8 CRUD Example from scratch - laravelcode.com</h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('BatterFirst.create') }}"> Create New Post</a>
</div>
</div>
</div>
#if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
#endif
<table class="table table-bordered">
<tr>
<th>No</th>
<th>Name</th>
<th>Runs</th>
<th>Balls</th>
<th>Sixs</th>
<th>Fours</th>
<th>Strick Rate</th>
</tr>
#foreach ($data as $key => $value)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $value->name }}</td>
<td>{{ $value->runs }}</td>
<td>{{ $value->overs }}</td>
<td>{{ $value->balls }}</td>
<td>{{ $value->sixs }}</td>
<td>{{ $value->fours }}</td>
{{-- <td>{{ $value->runs/$value->balls*100 }}</td> --}}
<td>#if ($value->runs > 0 and $value->runs ==0)
{{ $value->runs*100 }}
#elseif ($value->balls>0 and $value->runs ==0)
{{ $value->balls*$value->runs }}
#elseif ($value->balls==0 and $value->runs ==0)
{{ $value->balls * $value->runs }}
#elseif ($value->runs>0 and $value->balls>=0)
{{ $value->runs/$value->balls*100 }}
#endif
</td>
<td>
<form action="{{ route('BatterFirst.destroy',$value->id) }}" method="POST">
<a class="btn btn-info" href="{{ route('BatterFirst.show',$value->id) }}">Show</a>
<a class="btn btn-primary" href="{{ route('BatterFirst.edit',$value->id) }}">Edit</a>
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
#endforeach
</table>
{!! $data->links() !!}
#endsection
This is my BatterFirst/create.blade.php file
#extends('BatterFirst.layout')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Add New Product</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('BatterFirst.index') }}"> Back</a>
</div>
</div>
</div>
#if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form action="{{ route('BatterFirst.store') }}" method="POST">
#csrf
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" class="form-control" placeholder="Enter Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Runs:</strong>
<input type="number" name="runs" class="form-control" placeholder="Enter Runs">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Balls:</strong>
<input type="number" name="balls" class="form-control" placeholder="Enter Balls">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Sixs:</strong>
<input type="number" name="sixs" class="form-control" placeholder="Enter Sixs">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Fours:</strong>
<input type="number" name="fours" class="form-control" placeholder="Enter Fours">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
#endsection
I don`t know why this problem is showing.
Note: I just started to learn laravel
Its looking for the correct named table, since you have it in camel it should be batter_first you can change this via the model below;
class BatterFirst extends Model
{
use HasFactory;
protected $table = 'batterfirst';
protected $fillable = [
'name', 'runs', 'balls', 'sixs', 'fours'
];
}

Method App\Http\Livewire\Product::extension does not exist

I am learning laravel livewire, and this is my first time using livewire.
I am having trouble running my code on Laravel 8 with laravel-livewire. When I click submit always showing an error like that.
I'm don't know what's wrong and how to fix this
web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Livewire\Product;
Route::get('/products', Product::class);
Controller
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithFileUploads;
use App\Models\Product as ProductModel;
use Illuminate\Support\Facades\Storage;
class Product extends Component
{
use WithFileUploads;
public $name, $image, $description, $qty, $price;
public function previewImage()
{
$this->validate([
'image' => 'image|max:2048'
]);
}
public function store()
{
$this->validate([
'name' => 'required',
'image' => 'image|max:2048|required',
'description' => 'required',
'qty' => 'required',
'price' => 'required',
]);
$imageName = md5($this->image.microtime().'.'. $this->extension());
Storage::putFileAs(
'public/images',
$this->image,
$imageName
);
ProductModel::create([
'name' => $this->name,
'image' => $imageName,
'description' => $this->description,
'qty' => $this->qty,
'price' => $this->price
]);
session()->flash('info', 'Product created sSccessfully');
$this->name = '';
$this->image = '';
$this->description = '';
$this->qty = '';
$this->price = '';
}
}
In this is my blade code, i hope someone can help me. Thanks
<div>
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-body">
<h2 class="font-weight-bold mb-3">Product List</h2>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Image</th>
<th>Description</th>
<th>Qty</th>
<th>Price</th>
</tr>
</thead>
<tbody>
#foreach($products as $index=>$product)
<tr>
<td>{{ $index+1 }}</td>
<td>{{ $product->name }}</td>
<td>{{ $product->image }}</td>
<td>{{ $product->description }}</td>
<td>{{ $product->qty }}</td>
<td>{{ $product->price }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h2 class="font-weight-bold mb-3">Create Product</h2>
<form wire:submit.prevent="store">
<div class="form-group">
<label>Product Name</label>
<input wire:model="name" type="text" class="form-control">
#error('name') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<label>Product Image</label>
<div class="custom-file">
<input wire:model="image" type="file" class="custom-file-input" id="customFile">
<label for="customFile" class="custom-file-label">Choose Image</label>
</div>
#error('image') <small class="text-danger">{{ $message }}</small> #enderror
</div>
#if($image)
<label class="mt-2">Image Preview</label>
<img src="{{ $image->temporaryUrl() }}" class="img-fluid" alt="Preview Image">
#endif
<div class="form-group">
<label>Description</label>
<textarea wire:model="description" class="form-control"></textarea>
#error('description') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<label>Qty</label>
<input wire:model="qty" type="number" class="form-control">
#error('qty') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<label>Price</label>
<input wire:model="price" type="number" class="form-control">
#error('price') <small class="text-danger">{{ $message }}</small> #enderror
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Submit Product</button>
</div>
</form>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<h3>{{ $name }}</h3>
<h3>{{ $image }}</h3>
<h3>{{ $description }}</h3>
<h3>{{ $qty }}</h3>
<h3>{{ $price }}</h3>
</div>
</div>
</div>
</div>
use $this->image->extension() or \File::extension($this->image);
instead of $this->extensionin your code
$imageName = md5($this->image.microtime().'.'. $this->extension());
extension() is a method of FIle class thus needs a instance of Symfony\Component\HttpFoundation\File\UploadedFile class

Undefined variable: title (View: C:\xampp\htdocs\myproject\resources\views\categories\index.blade.php)

I try to make a page index.blade, but i getting error
Undefined variable: title (View: C:\xampp\htdocs\myproject\resources\views\categories\index.blade.php)
I am using laravel 5.4 PHP 7.0.33
Is there anything wrong with the code?
My Controller
<?php
namespace App\Http\Controllers;
use App\Category;
use Illuminate\Http\Request;
class CategoryController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$categories = Category::orderBy('created_at', 'DESC')->paginate(10);
return view('categories.index', compact('categories'));//
}
My index.blade
this is my view/categories/index.blade.php
#extends('layout.master')
​
#section('title')
<title>Manajemen Kategori</title>
#endsection
​
#section('content')
<div class="content-wrapper">
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">Manajemen Kategori</h1>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item active">Kategori</li>
</ol>
</div>
</div>
</div>
</div>
​
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
#card
#slot('title')
<div class="card">
<div class="card-header with-border">
<h3 class="card-title">{{ $title }}</h3>
</div>
<div class="card-body">
{{ $slot }}
</div>
{{ $footer }}
</div>
#endslot
#if (session('error'))
#alert
<div class="alert alert-{{ $type }} alert-dismissible">
{{ $slot }}
</div>
#endalert
#endif
​
<form role="form" action="{{ route('kategori.store') }}" method="POST">
#csrf
<div class="form-group">
<label for="name">Kategori</label>
<input type="text"
name="name"
class="form-control {{ $errors->has('name') ? 'is-invalid':'' }}" id="name" required>
</div>
<div class="form-group">
<label for="description">Deskripsi</label>
<textarea name="description" id="description" cols="5" rows="5" class="form-control {{ $errors->has('description') ? 'is-invalid':'' }}"></textarea>
</div>
#slot('footer')
<div class="card-footer">
<button class="btn btn-primary">Simpan</button>
</div>
</form>
#endslot
#endcard
</div>
<div class="col-md-8">
#card
#slot('title')
List Kategori
#endslot
#if (session('success'))
#alert(['type' => 'success'])
{!! session('success') !!}
#endalert
#endif
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<td>#</td>
<td>Kategori</td>
<td>Deskripsi</td>
<td>Aksi</td>
</tr>
</thead>
<tbody>
#php $no = 1; #endphp
#forelse ($categories as $row)
<tr>
<td>{{ $no++ }}</td>
<td>{{ $row->name }}</td>
<td>{{ $row->description }}</td>
<td>
<form action="{{ route('kategori.destroy', $row->id) }}" method="POST">
#csrf
<input type="hidden" name="_method" value="DELETE">
<i class="fa fa-edit"></i>
<button class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></button>
</form>
</td>
</tr>
#empty
<tr>
<td colspan="4" class="text-center">Tidak ada data</td>
</tr>
#endforelse
</tbody>
</table>
</div>
#slot('footer')
​
#endslot
#endcard
</div>
</div>
</div>
</section>
</div>
#endsection
My route web.php
Route::resource('/kategori', 'CategoryController',
['except' => ['create', 'show']]);
It should be like this
public function index()
{
$categories = Category::orderBy('created_at', 'DESC')->paginate(10);
$title = ''; //your title
return view('categories.index', compact('categories','title'));
}
because title not getting value from controller.
You dont pass variable title to view
Add some like this:
$title = 'Your title';
return view('categories.index', compact('categories','title'));
If title is a field of Category
If title is a field/member of Category model, then you would do {{ $category->title }}. I think this is the real error.
Otherwise
You need to define and send the variable as other have said.
$tile='Your Title';
return view('categories.index', compact('categories','title'));

Resources