Basic routes and BeerListController methods
This commit is contained in:
@@ -26,7 +26,7 @@ class ConfirmPasswordController extends Controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
protected $redirectTo = RouteServiceProvider::PROFILE;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
||||
@@ -26,7 +26,7 @@ class LoginController extends Controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
protected $redirectTo = RouteServiceProvider::PROFILE;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
||||
@@ -29,7 +29,7 @@ class RegisterController extends Controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
protected $redirectTo = RouteServiceProvider::PROFILE;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
||||
@@ -26,5 +26,5 @@ class ResetPasswordController extends Controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
protected $redirectTo = RouteServiceProvider::PROFILE;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class VerificationController extends Controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
protected $redirectTo = RouteServiceProvider::PROFILE;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
||||
@@ -2,9 +2,35 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\BeerList;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BeerListController extends Controller
|
||||
{
|
||||
//
|
||||
public function show(BeerList $list)
|
||||
{
|
||||
|
||||
return view('list.show', compact('list'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('list.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'title' => 'required',
|
||||
]);
|
||||
|
||||
$list = new BeerList;
|
||||
$list->title = $request->title;
|
||||
$list->user_id = auth()->user()->id;
|
||||
|
||||
$list->save();
|
||||
|
||||
return redirect('/profile');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('home');
|
||||
}
|
||||
}
|
||||
19
app/Http/Controllers/UserController.php
Normal file
19
app/Http/Controllers/UserController.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function index(User $user)
|
||||
{
|
||||
return view('profile', compact('user'));
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class RedirectIfAuthenticated
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
return redirect(RouteServiceProvider::PROFILE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,14 @@ class BeerList extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'user_id'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function beer()
|
||||
|
||||
@@ -42,7 +42,7 @@ class User extends Authenticatable
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function list()
|
||||
public function lists()
|
||||
{
|
||||
return $this->hasMany(BeerList::class);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
public const PROFILE = '/profile';
|
||||
|
||||
/**
|
||||
* The controller namespace for the application.
|
||||
|
||||
@@ -14,7 +14,8 @@ class CreateBeerListsTable extends Migration
|
||||
public function up()
|
||||
{
|
||||
Schema::create('beer_lists', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('id');
|
||||
$table->id();
|
||||
$table->string('title')->nullable();
|
||||
$table->integer('user_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ListBeersPivotTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('list_beers_pivot', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('id');
|
||||
$table->unsignedBigInteger('beer_id');
|
||||
$table->unsignedBigInteger('list_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('list_beers_pivot');
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">{{ __('Dashboard') }}</div>
|
||||
|
||||
<div class="card-body">
|
||||
@if (session('status'))
|
||||
<div class="alert alert-success" role="alert">
|
||||
{{ session('status') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{ __('You are logged in!') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
20
resources/views/list/create.blade.php
Normal file
20
resources/views/list/create.blade.php
Normal file
@@ -0,0 +1,20 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
Add list
|
||||
<form method="POST" action="{{ route('list.store') }}">
|
||||
@csrf
|
||||
<label for="title">
|
||||
List Name
|
||||
</label>
|
||||
<input class="bg-gray-300 border-black border-1" type="text" name="title">
|
||||
@if ($errors->has('title'))
|
||||
<span class="text-red-600" role="alert">
|
||||
<strong>{{ $errors->first('title') }}</strong>
|
||||
</span>
|
||||
@endif
|
||||
<button type="submit">
|
||||
Add List
|
||||
</button>
|
||||
</form>
|
||||
@endsection
|
||||
6
resources/views/list/show.blade.php
Normal file
6
resources/views/list/show.blade.php
Normal file
@@ -0,0 +1,6 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
{{ $list->title }}
|
||||
|
||||
@endsection
|
||||
15
resources/views/profile.blade.php
Normal file
15
resources/views/profile.blade.php
Normal file
@@ -0,0 +1,15 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
Profile
|
||||
</div>
|
||||
<a href="{{ route('list.create') }}">
|
||||
Add Beer list
|
||||
</a>
|
||||
@foreach (Auth::user()->lists as $list)
|
||||
<a href="{{ route('list.show', $list->id) }}">
|
||||
{{ $list->title }}
|
||||
</a>
|
||||
@endforeach
|
||||
@endsection
|
||||
@@ -25,7 +25,7 @@
|
||||
@if (Route::has('login'))
|
||||
<div class="hidden fixed top-0 right-0 px-6 py-4 sm:block">
|
||||
@auth
|
||||
<a href="{{ url('/home') }}" class="text-sm text-gray-700 underline">Home</a>
|
||||
<a href="{{ url('/profile') }}" class="text-sm text-gray-700 underline">Profile</a>
|
||||
@else
|
||||
<a href="{{ route('login') }}" class="text-sm text-gray-700 underline">Log in</a>
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\BeerListController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use App\Models\BeerList;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
/*
|
||||
@@ -19,4 +23,9 @@ Route::get('/', function () {
|
||||
|
||||
Auth::routes();
|
||||
|
||||
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
|
||||
Route::get('/profile', [UserController::class, 'index']);
|
||||
|
||||
//List Routes
|
||||
Route::get('/create-list', [BeerListController::class, 'create'])->name('list.create');
|
||||
Route::get('/list/{list}', [BeerListController::class, 'show'])->name('list.show');
|
||||
Route::post('/create-list', [BeerListController::class, 'store'])->name('list.store');
|
||||
|
||||
Reference in New Issue
Block a user