-1

I have a from group row with a dropdown that automatically fills with data form the table "clients".

<label for="client" class="text-muted font-weight-light text-center">{{ __('Client') }}</label>
<div class="form-group row">
    <div class="col-md-12">
       <select class="form-control" id="user" name="user">
       @foreach($clients as $client)
         <option value="{{$client->id}}">{{$client->firstname}} {{$client->lastname}} - {{$client->residence}} ({{$client->housing}} {{$client->housenr}})</option>
       @endforeach
       </select>
    </div>
</div>

this POST form pushes a whole form to a table named "tasks". Now the problem is that I'm using in this blade (for example) {{$client->residence}}, but I need to be able to do that in my controller in my insert function to push it to the database.

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function insert(Request $request)
{
    $clients = Clients::All();

    $id = auth()->user()->id;
    $title = $request->input('title');
    $startdate = $request->input('startdate');
    $enddate = $request->input('enddate');
    $starttime = $request->input('starttime');
    $endtime = $request->input('endtime');
    $description = $request->input('description');

    $data=array(
        "uuid"=>$id,
        "title"=>$title,
        "client"=>$client,
        "startdate"=>$startdate,
        "enddate"=>$enddate,
        "starttime"=>$starttime,
        "endtime"=>$endtime,
        "description"=>$description);
    DB::table('tasks')->insert($data);
    return redirect('/todo');
}

So what I would like to do is use the selected {{$client->id}} to get the information to push it to the task table in separate columns.

Hopefully it is clear what I mean.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Plance Development
  • 45
  • 1
  • 1
  • 13

2 Answers2

0

So I alreasy found the solution, just using queries solved my problem. now the only problem I'm facing now is that with $firstname = DB::select('select firstname from clients where id='.$clientid); I'm getting an array but for the export to the table im also using an array and I cant pass the $firstname array within the $data Array

$data=array(
        "uuid"=>$id,
        "title"=>$title,
        "residence"=>$residence[0],
        "startdate"=>$startdate,
        "enddate"=>$enddate,
        "starttime"=>$starttime,
        "endtime"=>$endtime,
        "description"=>$description,
        "firstname"=>$firstname,
        "lastname"=>$lastname,
        "housing"=>$housing,
        "housenr"=>$housenr

    );
    //dd($data);
    DB::table('tasks')->insert($data);
    return redirect('/todo');

errorcode picture

Plance Development
  • 45
  • 1
  • 1
  • 13
0

According to your above query the

$firsname should not a single vaule. It must be array or object. So please try using following code to access firstname.

You are also getting error for accessing object as string value.

  "firstname"=>$firstname->firstname,  //If firstname is object

OR

"firstname"=>$firstname['firstname'],  //If firstname is array