Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel-显示特定列的结果(分页)_Php_Laravel_Bootstrap 4_Pagination - Fatal编程技术网

Php Laravel-显示特定列的结果(分页)

Php Laravel-显示特定列的结果(分页),php,laravel,bootstrap-4,pagination,Php,Laravel,Bootstrap 4,Pagination,早上好 我正在寻求帮助,使我能够显示我的联盟每周时间表。我希望在MySQL中通过weekIndex列每周显示时间表 现在,我可以在一个刀片上显示所有明细表。希望下面我已经包含了足够的细节 调度控制器 namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Schedule; use App\Models\Team; use App\Models\League; use App\Models\Pla

早上好

我正在寻求帮助,使我能够显示我的联盟每周时间表。我希望在MySQL中通过weekIndex列每周显示时间表

现在,我可以在一个刀片上显示所有明细表。希望下面我已经包含了足够的细节

调度控制器


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Schedule;
use App\Models\Team;
use App\Models\League;
use App\Models\Player;
use App\Models\Standing;
use App\Models\Stat;

class SchedulesController extends Controller
{

function index(League $league, Team $teams, Schedule $schedules){
    $schedules = $league->schedule;
    $teams = $league->team;
    return view('schedules.index', compact('league','schedules', 'teams'));
}

function show($league, $schedule, Team $team){
    $schedule    = Schedule::where('leagueId', $league)->where('scheduleId', $schedule)->get();
    $league      = League::find($league);
    $team = $league->team;
    return view('schedules.show')->withSchedule($schedule)->withLeague($league)->withTeam($team);
}}
时间表模型


namespace app\Models;

use Illuminate\Database\Eloquent\Model;

class Schedule extends Model
{
    protected $table = 'schedule';
    public $primaryKey = 'scheduleId';

    public function profile()
    {
        return $this->hasMany('App\Models\Profile');
    }
    public function league()
    {
        return $this->belongsTo('App\Models\League', 'leagueId');
    }
    public function player()
    {
        return $this->hasMany('App\Models\Player', 'leagueId');
    }
    public function team()
    {
        return $this->hasMany('App\Models\Team', 'leagueId');
    }
    public function stat()
    {
        return $this->hasMany('App\Models\Stat', 'statId');
    }
    }

namespace app\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class League extends Model


    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'leagues';

    public $primaryKey = 'id';

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = true;

    /**
     * The attributes that are not mass assignable.
     *
     * @var array
     */
    protected $guarded = [
        'id',
    ];

    /**
     * The attributes that are hidden.
     *
     * @var array
     */
    protected $hidden = [];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    /**
     * Fillable fields for a Profile.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'shortName',
        'exportId',
        'platform',
        'taggable_id',
        'taggable_type',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id'            => 'integer',
        'name'          => 'string',
        'shortName'     => 'string',
        'exportId'      => 'string',
        'platform'      => 'string',
        'taggable_id'   => 'integer',
        'taggable_type' => 'string',
    ];

    /**
     * Get a validator for an incoming registration request.
     *
     * @param array $data
     *
     * @return array
     */
    public static function rules($id = 0, $merge = [])
    {
        return array_merge(
            [
                'name'      => 'required|min:3|max:50|unique:leagues,name'.($id ? ",$id" : ''),
                'shortName' => 'required|min:3|max:10|unique:leagues,shortName'.($id ? ",$id" : ''),
                'exportId'  => 'max:5',
                'platform'  => 'required',
            ],
            $merge
        );
    }

    /**
     * Get the profiles for the league.
     */
    public function profile()
    {
        return $this->hasMany('App\Models\Profile');
    }
    public function team()
    {
        return $this->hasMany('App\Models\Team', 'leagueId');
    }

    public function player()
    {
        return $this->hasMany('App\Models\Player', 'leagueId');
    }

    public function schedule()
    {
        return $this->hasMany('App\Models\Schedule', 'leagueId');
    }

    public function stat()
    {
        return $this->hasMany('App\Models\Stat', 'leagueId');
    }}
Schedule index.blade.php

@foreach($schedules as $schedule)
<tr>
   <td class="team-schedule__away"><a href=""><img src="/images/teams/64/{{$schedule->awayTeamId}}.png"></a></td>
   <td class="team-schedule__awayscore">{{$schedule->awayScore}}</td>
   <td class="team-schedule__at"><img src="/images/at.png"alt="at" width="50px"></td>
   <td class="team-schedule__homescore">{{$schedule->homeScore}}</td>
   <td class="team-schedule__home"><a href=""><img src="/images/teams/64/{{$schedule->homeTeamId}}.png"></a></td>
   <td class="team-schedule__tickets"><a href="./result/{{$schedule->scheduleId}}" class="btn btn-xs btn-default-alt btn-block ">Preview</a></td>
</tr>
@endforeach
@else
<p>
<div class="col-md-12">
   <div class="alert alert-danger"><button type="button" class="close" aria-label="Close"><span aria-hidden="true"></span></button> <strong>Schedules Not Found!</strong> Please try to sync your league following the included instructions HERE</div>
</div>
@endif
</tbody>

如果您只想获取本周的日程安排,可以在查询中使用碳,如下所示:

$schedules=$league->schedule->where('weekIndex',Carbon::now()->week())

编辑:如果要将它们分组,只需使用groupBy,如下所示:

$schedules=$league->schedule->groupBy('weekIndex')


我想这就是你要找的

嗨,谢谢你的迅速回复,但都没用。Carbon返回一个空白页,第二个建议声明collectionI中不存在该属性。我在MySQL中包含了我的表的一个图像。我希望所有weekIndex=0计划都显示在一个页面上,weekIndex=1显示在第二个页面上,依此类推,直到weekIndex=22我尝试了
$schedules=Schedule::where('weekIndex',$schedules)->paginate()到无增益。这将导致15个赛程加入到刀刃中。你的联盟模型看起来怎么样?如何创建计划关系?那就是说,
weekIndex
不存在。您可以按任何其他列分组,例如,
$schedules=$league->schedule->groupBy('awayTeamId')?我已将我的联盟模型添加到原始帖子中供您阅读。当我使用groupBy
awayTeamId
时,我会收到相同的错误,指出集合中不存在该属性