mirror of
https://github.com/brunofontes/shareit.git
synced 2025-12-15 12:02:08 -03:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
b99f6a5b68
|
|||
|
1f23753f70
|
|||
|
1fd78fe94a
|
|||
|
0bcefb43e6
|
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,6 +73,8 @@ class RegisterController extends Controller
|
|||||||
|
|
||||||
\Mail::to($user)->send(new Welcome($user));
|
\Mail::to($user)->send(new Welcome($user));
|
||||||
|
|
||||||
|
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();
|
||||||
@@ -28,7 +32,7 @@ class ItemController extends Controller
|
|||||||
* Stores the included item into database
|
* Stores the included item into database
|
||||||
* As the items are included on the Product view,
|
* As the items are included on the Product view,
|
||||||
* it must return to there after inclusion
|
* it must return to there after inclusion
|
||||||
*
|
*
|
||||||
* @return (view) The product view
|
* @return (view) The product view
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
@@ -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)
|
||||||
@@ -65,4 +69,4 @@ class ItemController extends Controller
|
|||||||
Item::deleteAndDetach($item);
|
Item::deleteAndDetach($item);
|
||||||
return redirect('product/' . $product);
|
return redirect('product/' . $product);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
@@ -17,7 +18,7 @@ class ProductController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the included product into database
|
* Stores the included product into database
|
||||||
*
|
*
|
||||||
* @return (view) The product view
|
* @return (view) The product view
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
@@ -29,7 +30,7 @@ class ProductController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a specified Product
|
* Delete a specified Product
|
||||||
*
|
*
|
||||||
* @param (int) $id The product id
|
* @param (int) $id The product id
|
||||||
*/
|
*/
|
||||||
public function delete(Request $request)
|
public function delete(Request $request)
|
||||||
@@ -55,14 +56,14 @@ class ProductController extends Controller
|
|||||||
$product->name = request('name');
|
$product->name = request('name');
|
||||||
$product->url = request('url');
|
$product->url = request('url');
|
||||||
$product->save();
|
$product->save();
|
||||||
return redirect('product/'.request('product'));
|
return redirect('product/' . request('product'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a specified Product
|
* Show a specified Product
|
||||||
*
|
*
|
||||||
* @param (int) $id The product id
|
* @param (int) $id The product id
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
@@ -70,8 +71,8 @@ class ProductController extends Controller
|
|||||||
$product = Product::fromAuthUser()->find($id);
|
$product = Product::fromAuthUser()->find($id);
|
||||||
|
|
||||||
if (!$product) {
|
if (!$product) {
|
||||||
return back();
|
session()->flash(flash::DANGER, "The product doesn't exist or doesn't belongs to you.");
|
||||||
|
return redirect('/product');
|
||||||
}
|
}
|
||||||
return view('product.show', compact('product'));
|
return view('product.show', compact('product'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
<!-- Styles -->
|
<!-- Styles -->
|
||||||
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
|
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<nav class="navbar navbar-expand-md navbar-light navbar-laravel">
|
<nav class="navbar navbar-expand-md navbar-light navbar-laravel">
|
||||||
@@ -26,7 +28,8 @@
|
|||||||
<a class="navbar-brand" href="{{ url('/') }}">
|
<a class="navbar-brand" href="{{ url('/') }}">
|
||||||
{{ config('app.name', 'Laravel') }}
|
{{ config('app.name', 'Laravel') }}
|
||||||
</a>
|
</a>
|
||||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
|
||||||
|
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
@@ -40,39 +43,47 @@
|
|||||||
<ul class="navbar-nav ml-auto">
|
<ul class="navbar-nav ml-auto">
|
||||||
<!-- Authentication Links -->
|
<!-- Authentication Links -->
|
||||||
@guest
|
@guest
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
|
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
|
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
|
||||||
</li>
|
</li>
|
||||||
@else
|
@else
|
||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
|
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown"
|
||||||
{{ Auth::user()->name }} <span class="caret"></span>
|
aria-haspopup="true" aria-expanded="false" v-pre>
|
||||||
|
{{ Auth::user()->name }} <span class="caret"></span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
|
||||||
|
<a class="dropdown-item" href="{{ route('logout') }}" onclick="event.preventDefault();
|
||||||
|
document.getElementById('logout-form').submit();">
|
||||||
|
{{ __('Logout') }}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
|
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
|
||||||
<a class="dropdown-item" href="{{ route('logout') }}"
|
@csrf
|
||||||
onclick="event.preventDefault();
|
</form>
|
||||||
document.getElementById('logout-form').submit();">
|
</div>
|
||||||
{{ __('Logout') }}
|
</li>
|
||||||
</a>
|
|
||||||
|
|
||||||
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
|
|
||||||
@csrf
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
@endguest
|
@endguest
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
@if ($flashMsg = session('primary'))
|
||||||
|
<div class="alert alert-primary text-center" role="alert">{{ $flashMsg }}</div>
|
||||||
|
@endif
|
||||||
|
@if ($flashMsg = session('danger'))
|
||||||
|
<div class="alert alert-danger text-center" role="alert">{{ $flashMsg }}</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<main class="py-4">
|
<main class="py-4">
|
||||||
@yield('content')
|
@yield('content')
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
||||||
|
</html>
|
||||||
@@ -15,7 +15,7 @@ Route::get('/', function () {
|
|||||||
return view('welcome');
|
return view('welcome');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/product', 'ProductController@index')->middleware('auth');
|
Route::get('/product', 'ProductController@index')->middleware('verified');
|
||||||
Route::get('/product/{product}', 'ProductController@show')->middleware('verified');
|
Route::get('/product/{product}', 'ProductController@show')->middleware('verified');
|
||||||
Route::post('/product', 'ProductController@store')->middleware('verified');
|
Route::post('/product', 'ProductController@store')->middleware('verified');
|
||||||
Route::patch('/product', 'ProductController@patch')->middleware('verified');
|
Route::patch('/product', 'ProductController@patch')->middleware('verified');
|
||||||
@@ -41,4 +41,4 @@ Auth::routes(['verify' => true]);
|
|||||||
Route::get('/home', 'HomeController@index')->name('home')->middleware('auth');
|
Route::get('/home', 'HomeController@index')->name('home')->middleware('auth');
|
||||||
Route::get('/help', function () {
|
Route::get('/help', function () {
|
||||||
return view('help');
|
return view('help');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user