Home > Software design >  Crud I made in Laravel 5.8 show error 419 page expires when sending data
Crud I made in Laravel 5.8 show error 419 page expires when sending data

Time:07-29

When I test or edit CRUD from other project it works fine, but when making CRUD eloquent myself I get 419 page expired and data not even stored... did anyone see the problem with my code? enter image description here enter image description hereps: 3 data here just seeder/manual, I want my CRUD successfully inserted fourth data

web.php

Route::get('/sistem', 'monocontroller@index');
Route::post('/sistem/date', 'monocontroller@newdate');

app\date.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class date extends Model
{
    protected $table = 'date';
    protected $fillable = ['bln','thn'];
}

monocontroller.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\date;

class monocontroller extends Controller
{
    public function index()
    {
        $date = date::all();
        return view('face', ['date' => $date]);
    }
public function newdate()
    {
        $this->validate($request,[
            'bln' => 'required',
            'thn' => 'required'
        ]);
 
        date::create([
            'bln' => $request->bln,
            'thn' => $request->thn
        ]);
        return back()->with('success','You have successfully added new date.');
    }
}

face.blade.php(form segment)

<form action="/sistem/date" method="post">
                    <select name="bln">
                    <option value="Januari">Januari</option>
                    <option value="Februari">Februari</option>
                    <option value="Maret">Maret</option>
                    <option value="April">April</option>
                    <option value="Mei">Mei</option>
                    <option value="Juni">Juni</option>
                    <option value="Juli">Juli</option>
                    <option value="Agustus">Agustus</option>
                    <option value="September">September</option>
                    <option value="Oktober">Oktober</option>
                    <option value="November">November</option>
                    <option value="Desember">Desember</option>
                    </select>
                    <input type="text" value="tahun" name="thn">
                    <input type="submit"  value="Masukkan Bulan Baru">
                </form>

Or is it one of those Laravel settings problem?

CodePudding user response:

Put CSRF field in your form:

<form ...>
    @csrf
</form>

CodePudding user response:

Write csrf token after form tag.

Token is requard for form submit.

csrf token define both way as below.

<form action="/sistem/date" method="post">

    @csrf 

    <input type="hidden" name="_token" value="{{ csrf_token() }}" />

</form>
  • Related