That error probably means that you are making a get or post request to a route that is not defined as being get or post. How are you calling that route in your view?
MethodNotAllowedHttpException in RouteCollection.php line 207:
NOTE: The Best Answer is not the only thing that should be read, it's the collection of all the answers that lead to the good result!
I've been having some trouble with the code that was given to create a random unique invite code. Follow the full history of this here: https://laracasts.com/discuss/channels/tips/group-table-creating-a-unique-invite-code
Some Errors have been resolved but I'm still stuck with one last error (I hope..) :
' MethodNotAllowedHttpException in RouteCollection.php line 207: '
To give you a clear view of what I currently have I'll post my code below:
Routes.php:
$router->post('invite', ['as' => 'invite.create', 'uses' => 'GroupController@createInvite']);
Invite.php model:
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class Invite extends Model {
protected $fillable = ['group_id', 'code', 'expires_at'];
protected $dates = ['expires_at'];
public function group()
{
return $this->belongsTo('App\Group');
}
public static function generate()
{
$exists = true;
while ($exists) {
$code = str_random(15);
$check = self::where('code', $code)->first();
if( ! $check){
$exists = false;
}
}
return $code;
}
}
GroupController.php:
<?php namespace App\Http\Controllers;
use App\Group;
use App\Invite;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Carbon\Carbon;
class GroupController extends Controller {
public function __construct()
{
$this->middleware('auth');
}
...
public function createInvite()
{
$group = Group::find(1); // Group ID you want to manage
$code = Invite::generate();
$invite = $group->invites()->create([
'code' => $code,
'expires_at' => Carbon::now()->addDays(7) // invite expires in 7 days
]);
//Then to check invite
return redirect()->back();
}
...
}
Anyone know why it's giving this error?
Thanks
I know this is in your routes.php
$router->post('invite', ['as' => 'invite.create', 'uses' => 'GroupController@createInvite']);
but just in case there is something conflicting show us all routes that are around there. Make sure there isn't a naming or method conflict.
Also all you have to do is {!! Form::open(['route' => 'invite.create']) !!}
And since the controller method is hardcoded to find Group::find(1) then this is ok, but you will eventually need to post an actual group id with a related view input and look for that in the method.
Please or to participate in this conversation.