There is a table migrated in the database Driver.
Table is given below.
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDriversTable extends Migration
{
public function up()
{
Schema::create('drivers', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('mobileNumber');
$table->string('licenseNumber');
$table->string('taxiNumber');
$table->string('address');
$table->decimal('latitude', 8, 6);
$table->decimal('longitude', 9, 6);
$table->string('status')->default('free');
$table->rememberToken();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('drivers');
}
}
There is a service ETaxiService.php, that contains the method to store database in the tables as,
public function createDriver($request) {
$driver = new Driver();
$driver->name = $request->input('name');
$driver->email = $request->input('email');
$driver->password = $request->input('password');
$driver->mobileNumber = $request->input('mobileNumber');
$driver->licenseNumber = $request->input('licenseNumber');
$driver->taxiNumber = $request->input('taxiNumber');
$driver->address = $request->input('address');
$driver->latitude = $request->input('latitude');
$driver->longitude = $request->input('longitude');
$driver->status = $request->input('status');
$driver->save();
return $driver;
}
There is a resource controllers i.e DriverController that contains store method which uses dependency injection of ETaxiService to use createDriver() method in it as,
public function store(Request $request) {
try {
$driver = $this->drivers->createDriver($request);
return response()->json($driver, 201);
} catch(Exception $e) {
return response()->json(['message' => $e->getMessage()], 500);
}
}
- Now my problem is that the store method of DriverController retrieves NULL values and get NULL data in database.
Routes for POST for both are below
Route::resource('v1/drivers', v1\DriverController::class, [
'except' => ['create', 'edit']
]);
During POST request I got this then
After execution of post request
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire