All I've done is laravel new and make:auth. I have spent a lot of time trying to understand how to get this functional, but I'm getting no where. I am building a site for an educational group that needs to manage their assets, they would like, I guess 3 levels of access?
-
user (registers to the site, can read and download files associated to whatever class they're taking from the professor)
-
instructors (users can become instructors by sending an email to the administrator, and having the admin give the access to the user. Instructors can post and update only their own content)
-
admin (has the ability to set users role and delete their accounts)
I've looked around some and noticed a few things, what if the admin gets deleted? Do you just create a new one on the back end?
I have 2 controllers, a User controller from make:auth and I created a Role controller so I can set up the relationship between the two, which I followed along here: https://laravel.com/docs/5.5/eloquent-relationships and read roles are generally belongsToMany. In both my controllers I have the relationship set as belongsToMany.
I have 3 migrations, users, password resets, and roles. I watched this video: https://laracasts.com/series/laravel-from-scratch-2017/episodes/30 and Jeffery talks about a pivot table, I went ahead and created the pivot table inside of my roles table, which is just integer('user_id');,
integer('role_id');, and a primary(['user_id', 'role_id']);
I'm basically just trying to build some simple functionality at the moment, like creating a new user with an admin role, but I don't even know how to do that, my migrations worked and all my tables are showing, but I'm not 100% sure what to do next, how do I create a user with the admin role? My roles table looks like this:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->timestamps();
});
Schema::create('user_roles', function (Blueprint $table) {
$table->integer('user_id');
$table->integer('role_id');
$table->primary(['user_id', 'role_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('roles');
Schema::dropIfExists('user_roles');
}
}
Question 1: I'm using the latest Laravel 5.5.3, and I saw another video where Jeffery just did php artisan generate:pivot or something like that, is there a command still you can write for pivot tables or do you just generally create a table with 2 ints holding the id's of what you want associated, and a primary key for both?
Question 2: do I need to have the 'user', 'instructor', admin' roles as things in my database? All I have in there right now is that it has to be a unique name: $table->string('name')->unique();
Question 3: for uploading files and content, does laravel have some kind of plugin you can use to mass upload files? The group I'm making this site for has lots of audio video and ppt files, I wonder is there a simple solution to going about uploading content to the site?
Question 4: If I have a user who uploads an audio file or video file, those things take a ton of space, how do you efficiently store things like that? Is there a way?
Thanks for any help!