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.
|
||||
|
||||
Reference in New Issue
Block a user