/** * Run the database seeds. * * @return void */ public function run() { // clear table \App\Work::truncate(); // add 1st row \App\Work::create(['user_id' => 1, 'title' => 'Software Engineer', 'company' => 'Google Inc']); // add 2nd row \App\Work::create(['user_id' => 1, 'title' => 'System Administrator', 'company' => 'IBM', 'start' => \Carbon\Carbon::createFromDate(2010, 01, 10)->toDateTimeString(), 'end' => \Carbon\Carbon::createFromDate(2014, 07, 22)->toDateTimeString()]); }
/** * Store a newly created resource in storage. * * @param StoreOrUpdateWorkRequest $request * @return RedirectResponse */ public function store(StoreOrUpdateWorkRequest $request) : RedirectResponse { $params = $request->all(); $params['sold'] = isset($params['sold']); $params['user_id'] = Auth::user()->id; $work = Work::create($params); if (file_exists(public_path('img/upload/' . $work->thumbnail))) { rename(public_path('img/upload/' . $work->thumbnail), public_path('img/work/' . $work->thumbnail)); } $this->clearUploads(); return Redirect::route('back.work.index')->with('message', ucfirst(trans('back/work.success_stored'))); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ public function store(WorksRequest $request) { // Create new entry $work = Work::create($request->all()); // Save work photos $this->savePhotos($request, $work); /* * Redirect to works route with session * of the newly created work */ return redirect()->route('dash.works')->with(['flash_entry_created' => true, 'flash_entry_id' => $work->id, 'flash_entry_title' => $work->title, 'flash_entry_route' => 'dash.works.edit']); }
/** * Saving new Work to database. * TODO Connect with gallery * @param Requests\StoreWorkRequest $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function store(\App\Http\Requests\StoreWorkRequest $request) { $videoCollection = []; foreach ($request['video'] as $_video) { $videoCollection[] = new \App\WorkVideo(['link' => $_video]); } unset($request['video']); $request['slug'] = str_slug($request['title'], "-"); $request['gallery_id'] = 1; $work = \App\Work::create($request->all()); $work->videos()->saveMany($videoCollection); return redirect(url('/admin/works/' . $work->type->slug)); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(\Illuminate\Http\Request $request) { $data = Request::all(); $this->validate($request, ['slug' => 'required', 'title' => 'required', 'category' => 'required', 'desc' => 'required', 'img' => 'required']); $thumbnail = $request->file('thumb'); $img = $request->file('img'); $now = \Carbon\Carbon::now(); $name = $now->minute . $now->day . $now->month . $now->year . "-" . $img->getClientOriginalName(); $path = public_path('img/uploads'); $img->move($path, $name); $thumbnail->move($path, 'thumb-' . $name); $data['thumbnail_path'] = '/img/uploads/thumb-' . $name; $data['img_path'] = '/img/uploads/' . $name; Work::create($data); }
public function run() { $faker = Faker\Factory::create(); for ($i = 0; $i < 15; $i++) { $work['title'] = $faker->name; $work['intro_text'] = $faker->sentence($words = rand(10, 15)); $work['lead'] = $faker->sentence($words = rand(10, 20)); $work['content'] = $faker->sentence($words = rand(20, 40)); $work['slug'] = $this->makeSlug($work['title']); $work['is_visible'] = 1; $work['is_featured'] = rand(0, 1); $work['gallery_id'] = 1; $work['type_id'] = rand(1, 5); \App\Work::create($work); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $input = $request->all(); $userId = Auth::user()['id']; $work = Work::where('user_id', $userId)->first(); //判断是否已经存在记录 if ($work == null) { $id['user_id'] = $userId; Work::create($id); } $work = Work::where('user_id', $userId)->first(); //判断来自第几个项目信息页面 if ($input['info_id'] == '1') { $name = $input['name']; $big_class = $input['big_class']; $small_class = $input['small_class']; $a = DB::update('update work set name=?,big_class=?,small_class=? where user_id=?', [$name, $big_class, $small_class, $userId]); return redirect('/work/create/2'); } if ($input['info_id'] == '2') { $aim = $input['aim']; $brief = $input['brief']; $detailed = $input['detailed']; $a = DB::update('update work set aim=?,brief=?,detailed=? where user_id=?', [$aim, $brief, $detailed, $userId]); return redirect('/work/create/3'); } if ($input['info_id'] == '3') { //判断请求中是否存在文件,如果存在则保存文件,否则存储为null if ($request->hasFile('materials') && $request->hasFile('document')) { $fileName1 = 'document' . '_' . $userId; $fileName2 = 'materials' . '_' . $userId; $path1 = 'file/document/'; $path2 = 'file/materials'; $request->file('document')->move($path1, $fileName1 . '.pdf'); $request->file('materials')->move($path2, $fileName2 . '.pdf'); $document_address = $fileName1; $materials_address = $fileName2; $a = DB::update('update work set document_address=?,materials_address=? where user_id=?', [$document_address, $materials_address, $userId]); } return redirect('/work/create/4'); } if ($input['info_id'] == '4') { //判断请求中是否存在文件,如果存在则保存文件,否则存储为null if ($request->hasFile('image') && $request->hasFile('video')) { $fileName1 = 'image' . '_' . $userId; $fileName2 = 'video' . '_' . $userId; $path1 = 'file/image/'; $path2 = 'file/video/'; $request->file('image')->move($path1, $fileName1 . '.jpg'); $request->file('video')->move($path2, $fileName2 . '.mp4'); $image_address = $fileName1; $video_address = $fileName2; $a = DB::update('update work set image_address=?,video_address=? where user_id=?', [$image_address, $video_address, $userId]); } } //存储作品后设置作品状态为schoolwait //根据userId获取workId $work = Work::where('user_id', $userId)->first(); $workId = $work['id']; //根据workId 设置WorkStatus $workStatus['work_id'] = $workId; $workStatus['status'] = 'schoolWait'; WorkStatus::create($workStatus); //填写完成所有资料,跳转到填写成功的页面 return redirect('/work/storeSuccess'); }