I have the same problem and don't have a clue on how to solve it.
My view is like this :
@extends('layouts.master')
@section('subtitle', 'Contact')
@section('content')
<div class="container col-md-8 col-md-offset-2">
<div class="card shadow-lg my-5 p-3 w-100">
<form method="POST" action="{{ url('tickets') }}">
@csrf
@foreach ($errors->all() as $error)
<p class="alert alert-danger">{{ $error }}</p>
@endforeach
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
<div class="card-body">
<h1 class="card-title">Submit a new ticket</h1>
<div class="form-group mt-5">
<label for="ticketTitle">
<h4 class="font-weight-bold">Title</h4>
</label>
<input type="text" class="form-control" id="ticketTitle" name="title" placeholder="Title">
</div>
<div class="form-group mt-5">
<label for="ticketContent">
<h4 class="font-weight-bold">Content</h4>
</label>
<textarea class="form-control" id="ticketContent" name="content" rows="5" aria-describedby="ticketContentHelp"></textarea>
<small id="ticketContentHelp" class="form-text text-muted help-text">Feel free to ask us any question.</small>
</div>
<div class="form-group form-group-indent">
<button type="button" class="btn btn-light btn-lg w-15 mb-2 mr-2" id="cancelButton">CANCEL</button>
<button type="submit" class="btn btn-info btn-lg w-15 mb-2" id="submitButton">SUBMIT</button>
</div>
</div>
</form>
My routes\web.php is like this :
<?php
Route::get('/', 'HomeController@index');
Route::get('about', 'AboutController@index');
Route::get('tickets/create', 'TicketsController@create');
Route::post('tickets', 'TicketsController@store');
My Form Request:
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class TicketFormRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required|min:3',
'content' => 'required|min:10',
];
}
}
My controller is like this :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\TicketFormRequest;
use App\Models\Ticket;
class TicketsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('tickets.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(TicketFormRequest $request)
{
$slug = uniqid();
$ticket = new Ticket([
'title' => $request->get('title'),
'content' => $request->get('content'),
'slug' => $slug,
'user_id' => 1
]);
$ticket->save();
return redirect('tickets')->with('status', 'Your ticket has been created! Its unique id is: '.$slug);
}
}
The model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Ticket extends Model
{
protected $fillable = ['title', 'content', 'slug', 'status', 'user_id'];
public function user()
{
return $this->belongsTo('User');
}
}
Url looks like this: http://firstwebsite.test/tickets/create
When I fill the fields and hit submit button it redirect to:
http://firstwebsite.test/tickets but with the following error:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message