I have a problem with inserting Data into Database.
All i have done till now is :
Create a Model with Controller and Migration via:
php artisan make:model Cars -mcr
So, now all of my files looks this way :
Cars - Model
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class Cars extends Model
{
}
AddCar.blade.php - View
<form action="" method="post">
<input type="text" name="brand" placeholder="Marka">
<input type="text" name="model" placeholder="Model">
<input type="text" name="doors" placeholder="Ilość drzwi">
<input type="text" name="priceHour" placeholder="Cena za godzinę">
<input type="text" name="priceDay" placeholder="Cena za dzień">
<input type="text" name="priceWeek" placeholder="Cena za tydzień">
<input type="text" name="priceMonth" placeholder="Cena za miesiąc">
<input type="text" name="priceYear" placeholder="Cena za rok">
<input type="submit" value="Osadź">
</form>
CarsController - Controller
namespace App\Http\Controllers;
use App\Cars;
use Illuminate\Http\Request;
class CarsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return "test";
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$cars = new Cars;
$cars->brand = $request->input('brand');
$cars->brand = $request->input('model');
$cars->brand = $request->input('type');
$cars->brand = $request->input('doors');
$cars->priceHour = $request->input('priceHour');
$cars->priceDay = $request->input('priceDay');
$cars->priceWeek = $request->input('priceWeek');
$cars->priceMonth = $request->input('priceMonth');
$cars->priceYear = $request->input('priceYear');
$cars->save();
return redirect('admin.AddCar');
}
web.php - Routing
Route::resource('/cars', 'CarsController');
Error I receiving after fill out all fields and click "Osadz" = submit is:
SQLSTATE[HY000]: General error: 1364 Field 'model' doesn't have a default value (SQL: insert into
cars
(brand
,priceHour
,priceDay
,priceWeek
,priceMonth
,priceYear
,updated_at
,created_at
) values (3, 3, 53, 3, 35, 3, 2018-01-30 09:36:57, 2018-01-30 09:36:57))
And my question is, what default value is missing in my code ?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2GvEzl4
via IFTTT
Aucun commentaire:
Enregistrer un commentaire