Php Laravel:插入tarificationtache的密码(语法错误或访问冲突)
我必须在'technicien'='technician'中插入'tache'='task'和'tarification'='price'Php Laravel:插入tarificationtache的密码(语法错误或访问冲突),php,laravel,Php,Laravel,我必须在'technicien'='technician'中插入'tache'='task'和'tarification'='price' Schema::create('tarificationtaches', function (Blueprint $table) { $table->increments('id'); $table->float('tarif', 8,2); $table->integer('tache_id
Schema::create('tarificationtaches', function (Blueprint $table) {
$table->increments('id');
$table->float('tarif', 8,2);
$table->integer('tache_id')->unsigned();
$table->foreign('tache_id')->references('id')->on('taches');
$table->integer('technicien_id')->unsigned();
$table->foreign('technicien_id')->references('id')-
>on('techniciens');
$table->datetime('deleted_at')->nullable();
$table->timestamps();
});
每个techncien必须设置“tache”,然后我想在我的函数中添加一个条件,以检查插入是否“tache”已存在如果是,则向我显示现有的“tache”,如果它未插入数据库中
public function store(Request $request)
{
$tarification = new tarificationtache();
$tarification ->tache_id = $request->input('tache_id');
$tarification ->Tarif =$request->input('Tarif');
$tarification->technicien_id = $request->input('technicien_id');
$tarification->save();
return redirect('technicien');
}
我已尝试此功能,但有一些错误
public function store(Request $request)
{
$tarification = new tarificationtache();
$tarification ->tache_id = $request->input('tache_id');
$tarification ->Tarif =$request->input('Tarif');
$tarification->technicien_id = $request->input('technicien_id');
$tarification = DB::select("select * FROM tarificationtaches where
technicien_id = 'technicien_id' and tache_id = input('tache_id')");
if(request($tarification) > 1)
echo "Ce technicien a cette tarification";
else{
$tarification->save();
}}
错误
SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION
projet2.input
does not exist (SQL: select * FROM tarificationtaches where \n
technicien_id = 'technicien_id' and tache_id = input('tache_id'))
根据我的理解,也许你需要这样的东西
public function store(Request $request)
{
$count = tarificationtache::where('technicien_id', $request->input('technicien_id'))
->where('tache_id', $request->input('tache_id'))
->count();
if ($count > 0) {
// TODO: adjust response according to your need
return response()->json(['error' => "Ce technicien a cette tarification"], 400);
} else {
$tarification = new tarificationtache;
$tarification->tache_id = $request->input('tache_id');
$tarification->Tarif = $request->input('Tarif');
$tarification>technicien_id = $request->input('technicien_id');
$tarification->save();
// TODO: adjust response according to your need
return response()->json($tarification);
}
}
您可以查看有关Laravel中的
count
或任何其他查询生成器方法的更多详细信息。mysql没有任何输入函数input('tache_id')
您的sql不正确我如何解决我的sql问题您的最终目标是什么?结果是什么-我真的不太理解你的问题。你已经将$tarification->tache\u id
设置为$request->input('tache\u id')
,,因此,在您的查询中使用$tarification->tache_id
。我添加了界面“我有几个技师每个人都必须有一个或多个任务,每个任务都必须有一个tarife”,因为这表明我必须为每个技师添加任务,但我想删除doublet,条件是检查spot是否可以与技师x或nnthak一起使用回答,但当我有相同的任务时,它会插入数据库,它显示如下{“tache_id”:“3”,“Tarif”:“253”,“technicien_id”:“1”,“updated_at”:“2018-08-17 09:29:27”,“created_at”:“2018-08-17 09:29:27”,“id”:11}Ups,我的错。它应该是$count>0
。我已经更新了我的答案非常感谢,如果我喜欢在同一界面上的popop上显示消息,我该怎么做?这里有几种方法可以做到这一点。最常见的方法是使用ajax提交表单,并在获得服务器响应后显示弹出窗口(例如,在jqueryajax
中的done()
)。这篇文章可以是一个良好的开端