Laravel:插入tarificationtache的条件(语法错误或访问冲突)

时间:2018-08-17 08:33:01

标签: 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')->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();
    });

每个技术人员都必须在其中添加“ 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'))

form to inset tache and tarif

1 个答案:

答案 0 :(得分:0)

根据我的理解,也许您需要这样的东西?

binary_crossentropy

您可以检查the doc以获得有关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中任何其他查询构建器方法的更多详细信息。