How to redirect from one page to another in Laravel?

Asked

Viewed 149 times

-2

I would like to say that I am extremely lay in PHP and Laravel, but I am trying to learn for a job. I’ve done a basic CRUD before with the tool but I have a question on a current project.

I created an application in Laravel, my goal is for a patient to register but first go through a home screen. In the 'views/layouts' folder, I changed the 'Welcome.blade.php' to my need, in it, I created a menu with the ul tag. This would be the home screen. I also created another file called 'cadastro.blade.php', which would be the registration screen. By clicking on a link, which is in this 'Welcome.blade.php' menu (the tag to), i would like the user to be directed to the 'registration.blade.php' page. I know that in 'Routes/web.php', there are the paths of the routes, but I don’t really know how to make it fit. For example, I would like that when accessing the route '/registration', I was able to go to the page 'cadastro.blade.php'. However, when I try this, it just appears 'Not found'. I’m sorry about the mistakes, like I said, I don’t really know how it works.

My code in 'Welcome.blade.php' (just a simple link):

    <label class="nome"> CADASTRO </label>
    <ul>
    <li>
    <hr>
    <a href="#">
        <span class="titulo"> Pré-cadastro de paciente </span>
    </a> 
    </li>
    </ul> 

My code in 'Routes/web.app':

Route::get('/', function () {
    return view('welcome');
});

Route::get('/pre-cadastro', 'PacientesController@create');

My 'Patientscontroller'':

class PacientesController extends Controller
{
    public function create(){
        return view('cadastro');
    }
}

Thank you.

1 answer

0


Hi, welcome to the O.R. I recommend reading about named Routes (routes named in en) and on the helper route. Done that come on

There is no route to /register and yes to /pre-registration, so the Not found 404.

If you wish that when accessing /register you "were able to go to the 'registration.blade.php' page" then change (in web.php):

Route::get('/pre-cadastro', 'PacientesController@create');

for

//nao entrarei em detalhes de boas práticas
Route::get('/cadastro', 'PacientesController@create')->name('nomeDaSuaRotaUnica');

And so that when you click on the link, you are "redirected" to Patientscontroller > create and the view "cadastro.blade.php" is rendered (note the part {{route('nameSuaRotaUnica')}}):

<label class="nome"> CADASTRO </label>
  <ul>
    <li>
      <hr>
      <a href="{{route('nomeDaSuaRotaUnica')}}">
        <span class="titulo"> Pré-cadastro de paciente </span>
      </a> 
    </li>
  </ul> 

Edit. I assumed the 8.x Standard is used but the example works at least in versions > 6.x

Browser other questions tagged

You are not signed in. Login or sign up in order to post.