/** * Show the application dashboard to the user. * * @return Response */ public function index() { $user_id = Auth::id(); $cats = Cat::getPet($user_id); // $cats = Cat::where('created_user_id', '=', $user_id); // return var_dump($cats); return view('home')->with('cats', $cats); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { // if (Auth::guest()) { return redirect('/auth/login'); } $input = $request->input(); $input['created_user_id'] = Auth::id(); $validator = Validator::make($input, ['name' => 'required|min:3', 'breed_id' => 'required']); $cat = Cat::create($input); // $cat = Cat::create($input); // var_dump( Storage::disk('local')); // exit; if ($request->hasFile('icon')) { $file = $request->file('icon'); $icon_validator = ['image/jpeg', 'image/bmp', 'image/png', 'image/gif']; if (!in_array($file->getClientMimeType(), $icon_validator)) { return redirect('cat/create')->with('cat', $input)->withError('The icon must be a photo or gif.'); } if ($validator->fails()) { return redirect('cat/create')->with('cat', $input)->withError('The icon must be a photo or gif.'); } if (file_exists($file)) { $uploadFile = new UploadFile(); $uploadFile->file = $file; $uploadFile->resource_id = $cat->id; $uploadFile->file_cd = Config::get('db_const.DB_FILE_FILE_CD_CAT_ICON_CODE'); $result = $uploadFile->saveFile(); if (!$result) { return redirect('cat/create')->withError('Icon updating error, please try again.'); } } } if ($cat->id) { return redirect('cat/' . $cat->id)->withSuccess('Cat has been created.'); } else { return redirect('cat/create')->withError('There are some errors, please try again.'); } }
public static function getPet($user_id) { $cats = Cat::where('created_user_id', '=', $user_id)->get(); return $cats; }