Created
April 7, 2016 16:55
-
-
Save amatriz/8342cf2ac80f306742aebc9eb0b3868b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use App\Http\Requests; | |
| use App\Http\Controllers\Controller; | |
| use Store; | |
| use App\categorium; | |
| use Illuminate\Http\Request; | |
| use Carbon\Carbon; | |
| use Session; | |
| use Input; | |
| use Symfony\Component\HttpFoundation\File\UploadedFile; | |
| class categoriaController extends Controller | |
| { | |
| protected $photo; | |
| public function __construct(Categorium $photo) | |
| { | |
| $this->photo = $photo; | |
| } | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return Response | |
| */ | |
| public function index() | |
| { | |
| $categoria = categorium::paginate(15); | |
| return view('categoria.index', compact('categoria')); | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return Response | |
| */ | |
| public function create() | |
| { | |
| return view('categoria.create'); | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @return Response | |
| */ | |
| public function store(Request $request){ | |
| $file = $request->file('pin'); | |
| if ($request->hasFile('pin')) | |
| { | |
| $fileName = $file->getClientOriginalName(); | |
| $extension = $file->getClientOriginalExtension() ?: 'png'; | |
| $folderName = '/imagem/'; | |
| $destinationPath = public_path() . $folderName; | |
| $safeName = str_random(10).'.'.$extension; | |
| $file->move($destinationPath, $safeName); | |
| $input = $request->all(); | |
| $savephoto = $this->photo->fill($input); | |
| $savephoto->pin = $safeName; | |
| $savephoto->save(); | |
| } | |
| categorium::create($request->all()); | |
| Session::flash('flash_message', 'categorium added!'); | |
| return redirect('categoria'); | |
| } | |
| /** | |
| * Display the specified resource. | |
| * | |
| * @param int $id | |
| * | |
| * @return Response | |
| */ | |
| public function show($id) | |
| { | |
| $categorium = categorium::findOrFail($id); | |
| return view('categoria.show', compact('categorium')); | |
| } | |
| /** | |
| * Show the form for editing the specified resource. | |
| * | |
| * @param int $id | |
| * | |
| * @return Response | |
| */ | |
| public function edit($id) | |
| { | |
| $categorium = categorium::findOrFail($id); | |
| return view('categoria.edit', compact('categorium')); | |
| } | |
| /** | |
| * Update the specified resource in storage. | |
| * | |
| * @param int $id | |
| * | |
| * @return Response | |
| */ | |
| public function update($id, Request $request) | |
| { | |
| $categorium = categorium::findOrFail($id); | |
| $categorium->update($request->all()); | |
| Session::flash('flash_message', 'categorium updated!'); | |
| return redirect('categoria'); | |
| } | |
| /** | |
| * Remove the specified resource from storage. | |
| * | |
| * @param int $id | |
| * | |
| * @return Response | |
| */ | |
| public function destroy($id) | |
| { | |
| categorium::destroy($id); | |
| Session::flash('flash_message', 'categorium deleted!'); | |
| return redirect('categoria'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment