'how can i store all details on login base
Schema::create('refunds', function (Blueprint $table) {
$table->id();
$table->bigInteger('user_id');
$table->string('name');
$table->bigInteger('contact');
$table->date('requested_at');
$table->timestamps();
});
This is user profile when user click on refund button then store all data of user in another table how its possible?
this is my controller
public function refundstore(Request $request)
{
$user_id = Auth::user()->id;
$refund = new Refund();
$refund->user_id = $id;
$refund->refund_id = $refund->id;
$refund->save();
return view('front.user.profile', compact('user_id', 'refund'));
}
This is view
<form action="{{ route('refundstore',Auth::user()->id)}}" method="post">
@csrf
<button class="applyRefund mt-2">Apply For Refund</button>
</form>
This is route
Route::post('refundstore', ['as' => 'refundstore', 'uses' => 'RefundController@refundstore']);
show error like this
SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into refunds (updated_at, created_at) values (2022-03-05 10:47:01, 2022-03-05 10:47:01))
Solution 1:[1]
First add type="submit" in your button
And change your Controller to this code :
public function refundstore(Request $request){
$user_id = Auth::user()->id;
$refund = new Refund();
$refund->user_id = $user_id;
$refund->refund_id = $refund->id;
$refund->save();
return view('front.user.profile', compact('user_id', 'refund'));
}
You got error on user_id doesnt have default value because your request a wrong data. In your controller you declare $user_id = Auth::user()->id; so that $user_id will find Auth user id that currently tried to make a refund request, if you wanted to make $id to find the user_id, you have to make a new function. In this case you already make $user_id = Auth::user()->id; so you can use $user_id instead of $id to speed up your time.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mansjoer |

