hi guys i am new in laravel so please bear with me.
im using laravel 5.4
what im trying to do is upon submitting the details, the user_id of the submitter will be inserted in the database.
can anyone help me please this my controller as of now.
<?php namespace App\Http\Controllers; use App\Permission; use App\Role; use App\RFQ; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class RFQController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $user = Auth::user(); $rfq_table = $user->rfq_table; return view('admin.sales.rfq.index',compact('rfq_table')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return view('admin.sales.rfq.create',compact('rfq_table')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $user=Auth::user(); $rfq= $user->rfq_table()->create($request->all()); return redirect()->route('admin.sales.rfq.index'); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } } my create.blade.php @extends('admin.layout.admin') @section('content') <h3>Create Roles</h3> <form action="{{route('rfq.store')}}" method="post" role="form"> {{csrf_field()}} <div class="form-group"> <label for="name">projectStart</label> <input type="date" class="form-control" name="projectStart" id="" placeholder="Name of role"> </div> <div class="form-group"> <label for="display_name">projectEnd</label> <input type="date" class="form-control" name="projectEnd" id="" placeholder="Display name"> </div> <div class="form-group"> <label for="description">budgetMax</label> <input type="number" class="form-control" name="budgetMax" id="" placeholder="Description"> </div> <div class="form-group"> <label for="description">budgetMin</label> <input type="number" class="form-control" name="budgetMin" id="" placeholder="Description"> </div> <div class="form-group"> <label for="description">itemDetails</label> <input type="text" class="form-control" name="itemDetails" id="" placeholder="Description"> </div> <div class="form-group"> <label for="description">qty</label> <input type="number" class="form-control" name="qty" id="" placeholder="Description"> </div> <div class="form-group"> <label for="description">itemName</label> <input type="text" class="form-control" name="itemName" id="" placeholder="Description"> </div> <button type="submit" class="btn btn-primary">Submit</button> </form> @endsectionndar0430 said:
what im trying to do is upon submitting the details, the user_id of the submitter will be inserted in the database.
Inserting it into where?
Your code here:
$rfq= $user->rfq_table()->create($request->all());
Inserts everything from the form into the rfq_table, I'm guessing. Is that where you want to store the user_id? If it is, why not insert the user_id at the same time?
whatarewe said:
ndar0430 said:
what im trying to do is upon submitting the details, the user_id of the submitter will be inserted in the database.
Inserting it into where?
Your code here:
$rfq= $user->rfq_table()->create($request->all());
Inserts everything from the form into the rfq_table, I'm guessing. Is that where you want to store the user_id? If it is, why not insert the user_id at the same time?
its actually i copy paste code from a tutorial on youtube..
not really understand what that says.
actually i understand everything aside from the function store.
so maybe there's an alternative code where the user id(the authenticated user who click submit) will be save on the database
ndar0430 said:
not really understand what that says.
actually i understand everything aside from the function store.
so maybe there's an alternative code where the user id(the authenticated user who click submit) will be save on the database
Well, reading the documentation will be a start. But here's what happens.
$rfq= $user->rfq_table()->create($request->all());
saves every field from the form into the rfq_table.There's a bit more to it than that. The rfq_table has a function called create()
written for it that takes the information and inserts it to the database. So look for that function, and it'll be able to tell you exactly how it stores the information in the database. When you can understand that, you'll be able to pull the authenticated user id in the controller and pass it along to create() for it to be stored as well.
https://laracasts.com/ also has lots of videos that'll be able to explain it more in-depth, and probably do a better job than I'm doing right now.
whatarewe said:
ndar0430 said:
not really understand what that says.
actually i understand everything aside from the function store.
so maybe there's an alternative code where the user id(the authenticated user who click submit) will be save on the database
Well, reading the documentation will be a start. But here's what happens.
- user types information into a form
- user clicks submit
- the browser submits information from the form to your controller
$rfq= $user->rfq_table()->create($request->all());
saves every field from the form into the rfq_table.There's a bit more to it than that. The rfq_table has a function called
create()
written for it that takes the information and inserts it to the database. So look for that function, and it'll be able to tell you exactly how it stores the information in the database. When you can understand that, you'll be able to pull the authenticated user id in the controller and pass it along to create() for it to be stored as well.https://laracasts.com/ also has lots of videos that'll be able to explain it more in-depth, and probably do a better job than I'm doing right now.
i now understand what u said but the thing is that i still don't know how to get the current login user ID to be inserted upon submission :( i hope you could help me im stuck here for days, we can do skype. i just really need it badly
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community