public function storeOld(Request $request) { $rules = ['name' => 'required|min:3', 'dir_track' => 'required']; $this->validate($request, $rules); Track::create($request->all()); return redirect('tracks'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['date' => 'required|date', 'distance' => 'required|numeric', 'time' => 'required', 'type_id' => 'required|numeric']); if ($validator->fails()) { return response()->json(['error' => 'invalid_data'], 422); } $user_id = 1; //Harcoded for now -> after implemented Authentication could be Auth::user()->id; $data = $request->all(); $data['user_id'] = $user_id; return Track::create($data); }
public function run() { $track = Track::create(['track' => 'Whole Numbers', 'description' => 'Whole Numbers', 'user_id' => 1]); $track->levels()->sync([1, 2, 3, 4, 5, 6, 7]); Track::create(['track' => 'Units of Measurement', 'description' => 'Units of Measurement', 'user_id' => 2])->levels()->sync([1, 2, 3, 4, 5, 6, 7]); Track::create(['track' => 'Data Analysis', 'description' => 'Data Analysis', 'user_id' => 3])->levels()->sync([5, 6, 7]); Track::create(['track' => 'Geometry', 'description' => 'Geometry', 'user_id' => 1])->levels()->sync([4, 5, 6, 7]); Track::create(['track' => 'Ratio and Percentage', 'description' => 'Ratio and Percentage', 'user_id' => 1])->levels()->sync([5, 6, 7]); Track::create(['track' => 'Speed', 'description' => 'Speed', 'user_id' => 2])->levels()->sync([6, 7]); Track::create(['track' => 'Algebra', 'description' => 'Algebra', 'user_id' => 1])->levels()->sync([7]); Track::create(['track' => 'Graphs', 'description' => 'Graphs', 'user_id' => 4])->levels()->sync([5, 6, 7]); Track::create(['track' => 'Uncategorized', 'description' => 'Uncategorized', 'user_id' => 1]); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(TrackRequest $request) { if (Gate::denies('admin')) { abort(403); } $artists_credit = ArtistCredit::create(['name' => 'tmp_name', 'artist_count' => 0, 'ref_count' => 0]); $req = $request->all(); // Request data $ac = []; // list of ArtistCreditNames $artists = []; // List of artists, just for counting foreach ($req['artist_credit']['work'] as $n => $work_id) { $artist_id = $req['artist_credit']['id'][$n]; $join_phrase = $req['artist_credit']['join'][$n]; $artists[$artist_id] = $join_phrase . ' ' . Artist::find($artist_id)->name; // artiat counter // Creating new ArtistCreditName $ac_new = ['artist_credit_id' => $artists_credit->id, 'artist_id' => $artist_id, 'work_type_id' => $work_id, 'position' => '', 'name' => Artist::find($artist_id)->name, 'join_phrase' => $join_phrase]; $ac[$artist_id . '_' . $work_id . '_' . $join_phrase] = new ArtistCreditName($ac_new); // Sets position. Not important for now there is no ordering in form // TODO make ordering in form $ac[$artist_id . '_' . $work_id . '_' . $join_phrase]->position = $n; // Saving ArtistCreditNames $ac[$artist_id . '_' . $work_id . '_' . $join_phrase]->save(); } $artists_credit->artist_count = count($artists); $artists_credit->ref_count = count($ac); $artists_credit->name = trim(implode(' ', $artists), ' &'); $artists_credit->save(); $req['artist_credit_id'] = $artists_credit->id; $track = Track::create($req); $genre = []; // genre list foreach ($req['genre'] as $n => $genre_id) { $genre_new = ['genre_id' => $genre_id, 'track_id' => $track->id]; $genre[$n] = new GenreTrack($genre_new); $genre[$n]->save(); } // return; return redirect()->route('track.show', ['track' => $track->id])->with('alert-success', [trans('htmusic.saved')]); }