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\Hash;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Foundation\Auth\RegistersUsers;
use App\FlashMessage;
class RegisterController extends Controller class RegisterController extends Controller
{ {
@ -72,7 +73,7 @@ class RegisterController extends Controller
\Mail::to($user)->send(new Welcome($user)); \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; return $user;
} }

View File

@ -5,13 +5,17 @@ namespace App\Http\Controllers;
use \App\Item; use \App\Item;
use \App\User; use \App\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\FlashMessage as flash;
class ItemController extends Controller class ItemController extends Controller
{ {
public function show($id) public function show($id)
{ {
$item = Item::find($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(); $users = $item->users()->get();
$otherItems = Item::where([['product_id', $item->product_id], ['id', '!=', $id]])->get(); $otherItems = Item::where([['product_id', $item->product_id], ['id', '!=', $id]])->get();

View File

@ -6,6 +6,7 @@ use \App\Item;
use \App\User; use \App\User;
use \App\Product; use \App\Product;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\FlashMessage as flash;
class ProductController extends Controller class ProductController extends Controller
{ {
@ -70,7 +71,7 @@ class ProductController extends Controller
$product = Product::fromAuthUser()->find($id); $product = Product::fromAuthUser()->find($id);
if (!$product) { 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 redirect('/product');
} }
return view('product.show', compact('product')); return view('product.show', compact('product'));