How to change school_id to a int for save in database?

Posted 3 months ago by irankhosravi

How to change school_id to a int for save in database? I have a problem for save to database in laravel and ajax. I want to school_id change to a variable (I think) for save. When I stored in database I get 500 error in network tag.

My code is here

<script type="text/javascript">
    $("#schools").submit(function (event) {
        event.preventDefault();
        province_id = $('#province_id').val();
        city_id = $('#city_id').val();
        center_id = $('#center_id').val();
        
        $.post("{{ route('schools-list.store') }}", {province_id:province_id, city_id:city_id, center_id:center_id}, function (data_school) {
            var school_id = {school_id: data_school.id} ;
            console.log(school_id);
        });
    });
</script>

Controller

public function store(Request $request, SchoolsList $schoolsList)
{
    if($request->ajax()) {
        $activity = new Activity();
        $activity->school_id = $request->school_id;
        $activity->cluster_id = $request->cluster_id;
        $activity->group_id = $request->group_id;
        $activity->save();
        return response()->json(['data_activity' => $request->all(), 'id' => $activity->id]);
    }
}

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.