Including FlashMessage Model

This commit is contained in:
Bruno F. Fontes 2018-09-20 00:18:30 -03:00
parent cb0c43ba0b
commit 36b62ffc8b
4 changed files with 24 additions and 7 deletions

11
app/FlashMessage.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class FlashMessage extends Model
{
const PRIMARY = 'primary';
const DANGER = 'danger';
}

View File

@ -8,6 +8,7 @@ use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use App\FlashMessage;
class RegisterController extends Controller
{
@ -72,7 +73,7 @@ class RegisterController extends Controller
\Mail::to($user)->send(new Welcome($user));
session()->flash('primary', 'Thanks for registering. Please, do not forget to validate your e-mail address.');
session()->flash(FlashMessage::PRIMARY, 'Thanks for registering. Please, do not forget to validate your e-mail address.');
return $user;
}

View File

@ -5,13 +5,17 @@ namespace App\Http\Controllers;
use \App\Item;
use \App\User;
use Illuminate\Http\Request;
use App\FlashMessage as flash;
class ItemController extends Controller
{
public function show($id)
{
$item = Item::find($id);
if (!$item || $item->product->user_id != \Auth::id()) return back();
if (!$item || $item->product->user_id != \Auth::id()) {
session()->flash(flash::DANGER, "The item doesn't exist.");
return back();
}
$users = $item->users()->get();
$otherItems = Item::where([['product_id', $item->product_id], ['id', '!=', $id]])->get();
@ -28,7 +32,7 @@ class ItemController extends Controller
* Stores the included item into database
* As the items are included on the Product view,
* it must return to there after inclusion
*
*
* @return (view) The product view
*/
public function store(Request $request)
@ -43,7 +47,7 @@ class ItemController extends Controller
$authUser = User::loggedIn();
$authUser->items()->create(['name' => request('item'), 'product_id' => request('product_id')]);
return redirect('product/'.request('product_id'));
return redirect('product/' . request('product_id'));
}
public function patch(Request $request)
@ -52,7 +56,7 @@ class ItemController extends Controller
$item = User::loggedIn()->items()->find(request('item'));
$item->name = request('name');
$item->save();
return redirect('item/'.request('item'));
return redirect('item/' . request('item'));
}
public function delete(Request $request)
@ -65,4 +69,4 @@ class ItemController extends Controller
Item::deleteAndDetach($item);
return redirect('product/' . $product);
}
}
}

View File

@ -6,6 +6,7 @@ use \App\Item;
use \App\User;
use \App\Product;
use Illuminate\Http\Request;
use App\FlashMessage as flash;
class ProductController extends Controller
{
@ -70,7 +71,7 @@ class ProductController extends Controller
$product = Product::fromAuthUser()->find($id);
if (!$product) {
session()->flash('danger', "The product doesn't exist or doesn't belongs to you.");
session()->flash(flash::DANGER, "The product doesn't exist or doesn't belongs to you.");
return redirect('/product');
}
return view('product.show', compact('product'));