G2A Many GEOs
SHARE
TWEET

laravel add image

a guest Apr 9th, 2020 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1)run : php artisan storage:link
  2. 2)table mestilah kena allocate space untuk image- so tambah dekat dalam migration (blueprint table tu, datatype is string)
  3. 3)kalau table ada dekat database, drop table tu dan pegi dekat table migrations, drop record berkenaan dngn table yg kita nk buang
  4. 4)php artisan migrate lagi skli
  5. 5) dekat form kena allocate tempat untuk upload gambar
  6. 6) make sure "name"= "ini" , ini kena sama dngn apa yg kita specify dalam model
  7. <input name="name">
  8. <input name="description">
  9. <input name="image">
  10.  
  11. simpan gambar/file
  12. code yg perlu ada dlm controller
  13.  
  14.  
  15. {
  16. //ini Untuk validation, field apa yg user perlu completekan sebelum system masuk ke database,
  17. $request->validate([
  18.             'user_id' => 'required',
  19.             'image' => 'mimes:jpeg,jpg,png|max:2048',
  20.             'agency_name' => 'required',
  21.             'reg_no' => 'required',
  22.             'category'=> 'required',
  23.             'person_name' => 'required',
  24.             'phone' => 'required',
  25.             'email' => 'required',
  26.             'address_1' => 'required',
  27.             'address_2' => 'required',
  28.             'city' => 'required',
  29.             'postcode' => 'required',
  30.             'state' => 'required',
  31.             'country' => 'required',
  32.         ]);
  33.         //cara store data menggunakan model
  34.         $profile = AgencyProfile::create($request->all());
  35.         //cara store image di storage dan update link di dalam table(database)
  36.         $profile->update(['image'=> $request->file('image')->store('agencyprofile', 'public')]);
  37.  
  38. }
  39.  
  40.  
  41. retrieve image link ke page/view
  42.  
  43. kalau call dia as image
  44.  
  45.  
  46. @foreach($datas as $data)
  47.     <img src="{{ asset("storage/$data->image") }}">
  48. @endforeach
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top