I'm trying to save data into a mysql DB with Laravel but i have this error: ROUTE [STORE] NOT DEFINED.
This is my Model: ` protected $table = 'devices'; protected $primaryKey = 'id';
protected $fillable = [
'username',
'mac_addr',
];
public static $rules = [
'username' => 'required|max:255',
'mac_address' => 'required|max:255'
];
This is my function store in the controller:
public function store(Request $request)
{
$input = new Device;
//On left field name in DB and on right field name in Form/view
$input->username = $request->username;
$input->mac_address = $request->mac_address;
$input->save();
return redirect()->route('store');
}
This my route:
Route::post('store', [DeviceController::class, 'store'])->name('store');
and finally my form:
@extends('backend.layouts.app')
@section('content')
<form action="{{ url('admin/store') }}" method="POST">
@csrf
<div class="form-group row">
<label class="col-sm-2 col-form-label">Username</label>
<div class="col-sm-10">
<input type="text" name="username" class="form-control" id="username">
</div>
</div>
<br>
<div class="form-group row">
<label class="col-sm-2 col-form-label">MAC ADDRESS</label>
<div class="col-sm-10">
<input type="text" name="mac_address" class="form-control" id="mac_address" placeholder="ex: 12:C4:65:8D:3A:00">
</div>
</div>
<br>
<button type="submit" class="btn btn-ghost-primary" id="register">Register</button>
<button type="reset" class="btn btn-ghost-primary" id="reset">Reset</button>
</form>
@endsection
CodePudding user response:
Route::post('admin/store', [DeviceController::class, 'store'])->name('store');
Isn't it ?
CodePudding user response:
Change your form's action :
action = "{{url('admin/store')}}"
by :
action = "{{route('store')}}"
Or just change your route by :
Route::post('admin/store', [DeviceController::class, 'store'])->name('store');