我现在有3张桌子在我的桌车上,我得到了我的2个外键系列和标记。
事实上,我的目标是创建一个录音。
我有错误信息......
SQLSTATE [23000]:完整性约束违规:1048 Le champ'name'nepeutêtrevide(null)(SQL:插入series
(name
,fk_mark
)
我的问题在于我的SerieController?
use Illuminate\Http\Request;
use App\Serie;
use App\Mark;
class SerieController extends Controller
{
public function index()
{
$series = Serie::oldest()->paginate(5);
return view('admin.series.index', compact('series'))
->with('i', (request()->input('page', 1)-1)*5);
}
public function create()
{
$marks = Mark::all();
return view('admin.series.create', compact('marks'));
}
public function store(Request $request)
{
Serie::create([
'name' => request('name'),
'fk_mark' => request('fk_mark')
]);
return redirect()->route('series.index')
->with('success', 'save');
}
我想我的问题出在我的CarController中,我的语法是否正确?
use Illuminate\Http\Request;
use App\Car;
use App\Serie;
use App\Mark;
class CarController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$cars = Car::oldest()->paginate(5);
return view('admin.cars.index', compact('cars'))
->with('i', (request()->input('page', 1)-1)*5);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$series = Serie::all();
$marks = Mark::all();
return view('admin.cars.create', compact('series' , 'marks'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
Car::create([
'matriculation' => request('matriculation'),
'fk_serie' => request('fk_serie'),
'fk_mark' => request('fk_mark')
]);
return redirect()->route('cars.index')
->with('success', 'save');
}
谢谢你的帮助,我真的被困了。
编辑:这是我在PhpMyAdmin上的表格
桌车
表系列
表标记
您应该验证您的请求。在您的情况下,请求中的name属性可能为null。