mirror of
https://github.com/brunofontes/shareit.git
synced 2024-11-23 20:10:52 +00:00
Including FlashMessage Model
This commit is contained in:
parent
cb0c43ba0b
commit
36b62ffc8b
11
app/FlashMessage.php
Normal file
11
app/FlashMessage.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class FlashMessage extends Model
|
||||||
|
{
|
||||||
|
const PRIMARY = 'primary';
|
||||||
|
const DANGER = 'danger';
|
||||||
|
}
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
@ -43,7 +47,7 @@ class ItemController extends Controller
|
|||||||
$authUser = User::loggedIn();
|
$authUser = User::loggedIn();
|
||||||
$authUser->items()->create(['name' => request('item'), 'product_id' => request('product_id')]);
|
$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)
|
public function patch(Request $request)
|
||||||
@ -52,7 +56,7 @@ class ItemController extends Controller
|
|||||||
$item = User::loggedIn()->items()->find(request('item'));
|
$item = User::loggedIn()->items()->find(request('item'));
|
||||||
$item->name = request('name');
|
$item->name = request('name');
|
||||||
$item->save();
|
$item->save();
|
||||||
return redirect('item/'.request('item'));
|
return redirect('item/' . request('item'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete(Request $request)
|
public function delete(Request $request)
|
||||||
|
@ -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'));
|
||||||
|
Loading…
Reference in New Issue
Block a user