1

When I try to access Route::has() from a view I get "Undefined class 'Route'". I don't get this error when I access this class from routes/web.php

All these files are automatically generated by Laravel. I'm using phpStorm.

how can I solve it?

thanks

app.blade.php:

@if (Route::has('login'))
     <li class="nav-item">
          <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
     </li>
@endif

home.blade.php:

@extends('layouts.app')

@section('content')
  <div id="result"></div>
@endsection

routes/web.php:

<?php
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
  if(Auth::check())
    return view('home');
  else
    return redirect()->route('login');
});

Auth::routes(["reset"=>false]);

Route::get('/home', 'HomeController@index')->name('home');

routes/api.php:

<?php
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Route;

  Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
   });
Juà
  • 11
  • 3
  • more details please. Which route? is this route defined in web.php or api.php? How do you ask for Route::has() in blade? please shere your routes/web.php and the snippet from your blade file – Mike Aron May 24 '20 at 21:38
  • From your view (blade) you can call route by `{{ route('route.name') }}` – STA May 24 '20 at 22:07
  • Thanks, I added the code, I just created a new project including basic Laravel user authentication, I'm not sure about how Laravel manages login and register routes – Juà May 24 '20 at 22:52

0 Answers0