Kam*_*ski 6 database database-connection model eloquent laravel-5
我将数据插入数据库时遇到问题。
我到目前为止所做的只是:
通过以下方式创建带有控制器和迁移的模型:
php artisan make:model Cars -mcr
Run Code Online (Sandbox Code Playgroud)
所以,现在我所有的文件看起来都是这样的:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Cars extends Model
{
}
Run Code Online (Sandbox Code Playgroud)
<form action="{{ action('CarsController@store') }}" method="post">
{{ csrf_field() }}
<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>
Run Code Online (Sandbox Code Playgroud)
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');
}
Run Code Online (Sandbox Code Playgroud)
Route::resource('/cars', 'CarsController');
Run Code Online (Sandbox Code Playgroud)
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCarsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cars', function (Blueprint $table) {
$table->increments('id');
$table->string('brand');
$table->string('model');
$table->string('type');
$table->integer('doors');
$table->string ('priceHour')->nullable();
$table->string('priceDay')->nullable();
$table->string('priceWeek')->nullable();
$table->string('priceMonth')->nullable();
$table->string('priceYear')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('cars');
}
}
Run Code Online (Sandbox Code Playgroud)
填写所有字段并单击“ Osadz” =提交后,我收到错误消息:
SQLSTATE [HY000]:常规错误:1364字段'模型'不具有默认值(SQL:插入到
cars
(brand
,priceHour
,priceDay
,priceWeek
,priceMonth
,priceYear
,updated_at
,created_at
)的值(3,3,53,3,35,3,2018- 01-30 09:36:57,2018-01-30 09:36:57))
我的问题是,我的代码中缺少什么默认值?
归档时间: |
|
查看次数: |
16826 次 |
最近记录: |