1

I want to go create.php If user click button that not logged in user redirect to login page in index.blade.php.

But only page URL is changed. Here's my codes.

index.blade.php

<button class="btn btn-default btn-sm" type="button" aria-expanded="false" onclick="location.href='{{ route('board.create') }}' ">글쓰기</button>

Route

Route::group(['middleware' => 'auth'], function(){
Route::get('board/create', ['as' => 'board.create', 'uses' =>'BoardController@create']);
});

Controller

public function create() {

    return view('board.create');

}

View create.blade.php

@extends('layouts.app')
@section('content')
.......
@endsection
jungmyung
  • 319
  • 3
  • 13

1 Answers1

0

I assume that you need to redirect user into login page if not logged in otherwise redirect to create page. With this, Please check below button with if statement. You just need to replace my below snippet at your index.blade.php

@if(Auth::user())
   <button class="btn btn-default btn-sm" type="button" aria-expanded="false" onclick="location.href='{{ route('board.create') }}' ">글쓰기</button>
@else
   <button class="btn btn-default btn-sm" type="button" aria-expanded="false" onclick="location.href='{{ url('/login') }}' ">글쓰기</button>
@endif

Let me know you have any query OR I'm wrong here.

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57