irankhosravi
1 year ago

How to store id in show function in laravel 5-4

Posted 1 year ago by irankhosravi

In my controller in my show function in laravel I want the get the id that shows in browser show when I browse it it shows like this.

http://localhost:8000/admin/school/1

Now how to save id of schools table to school_id of requisitions.

public function store(Request $request, School $school)
{
    $school_id = $request->get($school->id);
    $requisition = new Requisition();
    $requisition->user_id = auth()->user()->id;
    $requisition->school_id = $school_id;
    $requisition->type = $request->application;
    $requisition->status = 0;
    $requisition->approved = 0;
    $requisition->save();
    return redirect(route('school.index'));
}

Model

class Requisition extends Model
{
    public function schools()
    {
        return $this->belongsTo(School::class, 'school_id');
    }
}

create.blade.php

<form action="{{ route('requisitions.store')}}" method="post">
    {{ csrf_field() }}
    <div class="radio">
        <label for="school">School</label>
        <input type="radio" value="1" id="school" name="application">
        <br>
        <label for="equipment">Equipment</label>
        <input type="radio" value="2" id="equipment" name="application">
        <br>
        <label for="level">Level</label>
        <input type="radio" value="3" id="level" name="application">
        <br>
        <label for="place">Place</label>
        <input type="radio" value="4" id="place" name="application">
        <br>
        <label for="tax">Tax</label>
        <input type="radio" value="5" id="tax" name="application">
        <br>
        <label for="reactivation">Reactivation</label>
        <input type="radio" value="6" id="reactivation" name="application">
        <br>
        <button type="submit" class="btn-warning btn">Send</button>
    </div>
</form>

I did send already in create function.

public function create()
{
    $school = School::all();
    return view('Admin.requisitions.create', compact('school'));
}

Please sign in or create an account to participate in this conversation.