@Kryptonit3 Well the user that creates the group, gets access to the invite code but he/she does not need to be an administrator.
Once a second user joins the group through the invite code, he/she has the same access to everything in the group.
I tried everything stated above.
Error fix #1: was with the 'php artisan migrate' where I had to change the:
->onDelete('update')
To:
->onDelete('cascade')
Then, I ran into an error when trying to create the invite code.
This is how I am testing out the code:
I simply made a Group to test it out (has the id=1).
In my GroupController.php I added a 'createInvite' function like this:
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 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
]);
return 'invite code created';
}
...
}
and in my routes.php page trigger the function through the link '/invite by doing this:
$router->post('invite', ['as' => 'invite.create', 'uses' => 'GroupController@createInvite']);
But when doing this, I got this error:
FatalErrorException in Invite.php line 31:
Call to a member function count() on a non-object
Error fix #2:
public static function generate()
{
$exists = true;
while ($exists) {
$code = str_random(15);
$check = self::where('code', $code)->first();
if( ! $check){ // <-- Error
$exists = false;
}
}
return $code;
}
To fix the error stated above I removed the '->count()'
Now I'm getting a 'MethodNotAllowedHttpException in RouteCollection.php line 207:'
I've created a new post seeing this is more of a Code Review. This is the link:
https://laracasts.com/discuss/channels/code-review/methodnotallowedhttpexception-in-routecollectionphp-line-207-2