如何显示与自身相关的school_id

时间:2018-08-25 20:49:54

标签: laravel-5.4

我要显示与自身相关的school_id

ActivityController.php

public function read_activity()
{
    $activities = Activity::with('group', 'cluster')->where('school_id', 'LIKE', '_school_id')->get();
    return response()->json($activities);
}

public function store(Request $request)
{
    if($request->ajax()) {
        $activity = new Activity();
        $activity->school_id = intval($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]);
    }
}

对于阿贾克斯学校

.............
.............
.............
$.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};
    school_id = (school_id['school_id']);
    _school_id = school_id;
});

用于ajax活动

    $("#activity-forms").submit(function (event) {
        event.preventDefault();
        cluster_id = $('#cluster_id').val();
        group_id = $('#group_id').val();
        console.warn(_school_id);
        $.post("{{ route('activity.store') }}", {_school_id:_school_id, cluster_id:cluster_id, group_id:group_id}, function (data_activity) {
            console.log(data_activity);
            load_activity();
        });
    });

web.php

Route::get('/read-activity', 'Admin\ActivityController@read_activity');
Route::namespace('Admin')->prefix('admin')->middleware('auth')->group(function (){
    $this->resource('schools-list', 'SchoolsListController');
    $this->resource('activity', 'ActivityController');
});

我尝试并编辑了您的答案和帖子,但没有成功。而且我只想显示school_id =数字本身。

Activity

0 个答案:

没有答案