0
votes

i try to input value of first_name and last_name from table students to column name of table users here is my studentcontroller

  public function store(Request $request)
    {
        $user = new User;
        $user->name = $request->first_name&&$request->last_name;
        $user->save();

        $student = new Santri;
        $student->user_id = $user->id;
        $student->first_name = $request->get('first_name');
        $student->last_name = $request->get('last_name');
        $student->save();

 return redirect()->route('student.index');
    }

then the result value='1' in column name at table user

how to get value first_name and last_name sorted to column name in table user?

1

1 Answers

3
votes

Don't use &&, use php's concatenation operator.

$user->name = $request->first_name . $request->last_name;

The reason why you're getting 1 as a result is because you're using the && Logical operator. Because php is very weakly typed it assumes anything that isn't a null or a 0 is "True", and by comparing "True" && "True" you get "True" which is 1