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

Posted 6 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.

Reply to

Use Markdown with GitHub-flavored code blocks.