route.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::resource('discussions', 'PostController');
Route::get('/', 'PostController@index');
Route::get('/user/register', 'UsersController@register');
Route::get('/user/login', 'UsersController@login');
Route::post('/user/register', 'UsersController@store');
Route::post('/user/login', 'UsersController@signin');
Route::get('/user/logout', 'UsersController@logout');
PostController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Discussion;
class PostController extends Controller
{
public function index()
{
$discussions = Discussion::all();
return view('form.index',compact('discussions'));
}
public function create()
{
return view('form.create');
}
public function show($id)
{
$discussion = Discussion::findOrFail($id);
return view('form.show', compact('discussion'));
}
}
UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use Illuminate\Support\Facades\Auth;
class UsersController extends Controller
{
public function login()
{
return view('users/login');
}
public function logout()
{
if(\Auth::check()) \Auth::logout();
return redirect('/');
}
public function signin(Requests\UserLoginRequest $request)
{
if (\Auth::attempt([
'email'=>$request->get('email'),
'password'=>$request->get('password'),
])){
return redirect('/');
}
\Session::flash('user_login_failed','이메일주소 혹은 비밀번호가 틀렸습니다.');
return redirect('/user/login')->withInput();
}
public function register()
{
return view('users/register');
}
public function store(Requests\UserRegisterRequest $request)
{
User::create(array_merge($request->all(), ['avatar' => '/images/default.jpg']));
//send email
return redirect('/');
}
}