Remember, in the very beginning, we had created a structure for the Vehicle model? Let me remind you:
Migration file:
Schema::create('vehicles', function (Blueprint $table) { $table->id(); $table->foreignId('user_id')->constrained(); $table->string('plate_number'); $table->timestamps(); $table->softDeletes();});
app/Models/Vehicle.php:
use Illuminate\Database\Eloquent\SoftDeletes; class Vehicle extends Model{ use HasFactory; use SoftDeletes; protected $fillable = ['user_id', 'plate_number'];}
So now we need API endpoints for a user to manage their vehicles. This should be a typical CRUD, with these 5 methods in the Controller:
- index
- store
- show
- update
- delete
So, let's generate it. This is our first Controller without the "Auth" namespace, and let's add a few Artisan flags to generate some skeleton for us...