/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { if (Gate::denies('admin')) { abort(403); } // TODO "Add Link" button $out = ['form_route' => ['route' => 'link.store', 'method' => 'POST', 'class' => 'form-horizontal']]; if (count(Request::old())) { $rq = Request::old(); $out['link'] = new Link($rq); if (isset($rq['artist_id']) && is_array($rq['artist_id'])) { $out['link']->artists = Artist::whereIn('id', $rq['artist_id'])->get(); } if (isset($rq['release_id']) && is_array($rq['release_id'])) { $out['link']->releases = Release::whereIn('id', $rq['release_id'])->get(); } if (isset($rq['track_id']) && is_array($rq['track_id'])) { $out['link']->tracks = Track::whereIn('id', $rq['track_id'])->get(); } } else { $rq = Request::all(['artist_id', 'release_id', 'track_id']); $out['link'] = new Link(); if (isset($rq['artist_id']) && (int) $rq['artist_id'] > 0) { $out['link']->artists = Artist::where('id', (int) $rq['artist_id'])->get(); } if (isset($rq['release_id']) && (int) $rq['release_id'] > 0) { $out['link']->releases = Release::where('id', (int) $rq['release_id'])->get(); } if (isset($rq['track_id']) && (int) $rq['track_id'] > 0) { $out['link']->tracks = Track::where('id', (int) $rq['track_id'])->get(); } } return view('links.form', $out); }
public function search($str) { $out = Release::where('name', 'LIKE', $str . '%')->get(['id', 'name', 'artist_credit_id']); foreach ($out as &$row) { $row->artist = $row->credit()->first()->name; } return $out; }