Route [/createhotel] not defined. laravel 5.4

This is my index view page.

@extends('layouts.app')

<!DOCTYPE html>
<html lang="en">
<head>
<link href="css/hotel.css" rel="stylesheet" type="text/css"/>

</head>
<body>

@section('content')
<h2>Hotels</h2>

<div class="container-fluid sug-1">
    <div class="ui_column is-12 h1 ui_header sug-1head">{{ $data[0]->city}}&nbsp;
    </div>
<div style="display:flex; flex-direction: row; justify-content: center; align-items: center">   

@for ($i = 0; $i < 4; $i++)

  <div  class= "img__wrap">
  <form method="get" action="/hotel/viewpost.blade.php"> 
    <a href="/hotel/viewpost/{{$data[$i]->id }}"><img class = "img__img" src={{asset($data[$i]->image)}} alt="Logo" style="width:90%;height:90%" ></a>
    <p class = "img__description"> {{$data[$i]->name}} <br> {{$data[$i]->rating}}<br> {{$data[$i]->price}}</p>
  </form>
      </div>
@endfor

 <input class="sug1btn"  type=Button id="allsugbtn" onclick="findHotels();" value="See all"/>

</div>

@endsection

</body>
</html>

This is controller for my index:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HotelController extends Controller
{
   public function index()
   {
        $hotelData['data'] = \DB::table('hotels')->get();
        if(count($hotelData) > 0)
        {
            return view("hotel.index",$hotelData);
        }
        else
        {
            return view("hotel.index");
        }
   } 


}

I created a route from my index to viewpost i.e. following code:

@extends('layouts.app')

<!DOCTYPE html>
<html lang="en">
<head>
      <link href="css/hotel.css" rel="stylesheet" type="text/css"/>



</head>
<body>

@section('content')

<div class="container-fluid sug-1">
    <div class="ui_column is-12 h1 ui_header sug-1head">
    </div>
<div style="display:flex; flex-direction: row; justify-content: left; align-items: left">   

 <div class="card">
  <img src={{asset($data->image)}} alt="Image" style="width:100%">
  <div class="container">
    <h4><b>{{$data->name}}</b></h4> 
    <p>Rating: {{$data->rating}}<br>Price: {{$data->price}}</p> 
  </div>
</div>

 <button href="{{ route('/createhotel') }}" type="button" class="btn btn-default">Left</button>
</div>

<h2>Reviews</h2>

@foreach ($reviews as $review)
    <p>{{ $review->user_name }}<br>{{ $review->description }}</p>
    <br><br><br>

@endforeach

@endsection

</body>
</html>

This is HotelPostController for my viewpost and createhotel:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HotelPostsController extends Controller
{
    public function show($hotelviewid)
   {
        $imagedata['data'] = \DB::table('hotels')->select('id','image','name','city','rating','price' )->where('id', $hotelviewid)->first();

        $reviewdata['reviews'] = \DB::table('hotel_reviews')->where('hotel_id', $hotelviewid)->get();


        return view("hotel.viewpost",$imagedata,$reviewdata);
   }

   public function createhotel()
   {
        return view("hotel.createhotel");
   }
}

This is web.php routes file:

Route::get('/', 'HotelController@index');
Route::get('/hotel', 'HotelController@index');
Route::get('/hotel/viewpost/{hotelviewid}', 'HotelPostsController@show');
Route::get('travelapp.me/hotel/viewpost/createhotel, 'HotelPostsController@createhotel');

The problem I am facing is that in views folder I have created a sub folder by name of hotel, it has 3 files index, viewpost and createhotel. the frst page is index and when a user clicks on some post it opens in viewpost. Now from there I want to create a button that goes to the third page i.e. creathotel. I have created a funtion in controller also added routes but it gives the error of undefined routes.

Change

Route::get('travelapp.me/hotel/viewpost/createhotel, 'HotelPostsController@createhotel');

to

Route::get('/hotel/viewpost/createhotel, 'HotelPostsController@createhotel');

And your button to go to create page:

<a href="{{url('/hotel/viewpost/createhotel')}}">Create Hotel</a>

The method url() will give you the full URL automatically. You just need to create URL from root (/) and you dont have to attache full domain.

You can do like this (Just an example)

Route::get('/hotel-create, 'HotelPostsController@createhotel');

and button to go to that page

 <a href="{{url('/hotel-create')}}">Create Hotel</a>

Now in this example, When you click on Create Hotel link, this will gonna call the method createhotel() of HotelPostsController controller. Update: Problem In your controller you are not passing any data to the view

public function createhotel()
{
     return view("hotel.createhotel");
}

So how can you access the variable called $data on

<img src={{asset($data->image)}} alt="Image" style="width:100%">

Solution: (Pass your data to template)

public function createhotel()
{
    $imagedata['data'] = \DB::table('hotels')->select('id','image','name','city','rating','price' )->where('id', $hotelviewid)->first();

     $reviewdata['reviews'] = \DB::table('hotel_reviews')->where('hotel_id', $hotelviewid)->get();
     return view("hotel.createhotel",$imagedata,$reviewdata);
 }

php - How to solve route not defined in laravel 5.3?, [SOLVED] Laravel: route [/create] not defined. I have been trying to figure out what I'm doing wrong here for quite I have been trying to figure out  Questions: I am creating an application in Laravela and when I try to visit my url, for example: h

The route() helper method accepts the name as the parameter, not the actual route.

route('create') is what you want. To use the url, url('/hotel/create').

[SOLVED] Laravel: route [/create] not defined., Laravel Version: 5.4.21 PHP Version: 7.1 Description: InvalidArgumentException in UrlGenerator.php line 304: Route [home] not defined. The most concise screencasts for the working developer, updated daily. There's no shortage of content at Laracasts. In fact, you could watch nonstop for days upon days, and still not see everything!

Route::get('/hotel/create', 'HotelReviewController@create')->name('create');

change it to

 Route::get('/hotel/create', 'HotelReviewController@create')->name('createhotel');

it will work i hope. you are using named route read here about routing. https://laravel.com/docs/5.6/routing#named-routes

[5.4] Route not defined (consistently configure the name of the router , If you are defining a route that redirects to another URI, you may use the Route::​redirect method. This method provides a convenient shortcut so that you do not  Route not defined when the route is defined Posted 2 years ago by dcaldessa. Hello, I created a new route. Proudly hosted with Laravel Forge and DigitalOcean.

in your index action value filled by a view blade page and it seems wrong

<form method="get" action="/hotel/viewpost.blade.php">

and in viewpost you need to change {{ route("/create") }} to {!! route("create")!!}

Routing - Laravel, Master, 7.x, 6.x · 5.8 · 5.7 · 5.6 · 5.5 · 5.4 · 5.3 · 5.2 · 5.1 · 5.0 · 4.2 Guards define how users are authenticated for each request. If your application is not using Eloquent, you may use the database authentication driver which Now that you have routes and views setup for the included authentication controllers, you are  Basic Routing. The most basic Laravel routes accept a URI and a Closure, providing a very simple and expressive method of defining routes: Route::get('foo', function { return 'Hello World'; }); The Default Route Files. All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically

Authentication - Laravel, Hello, I created a new route Route::resource('/admin/users/roles/', '​AdminRolesController'); then defined a view in the AdminRolesController  Laravel 5.4 - use a custom attribute model in a co Laravel Query builder : left join, select, and whe how to create an array for reply keyboard for tele laravel mutliple row save to database; LARAVEL - Not able to call a function inside a con Laravel 5.4 route group and resource mess up the p

Route not defined when the route is defined, index] not defined. Posted 8 months ago by JOHNMAC. I'm trying to get a categories page but it says: Route [admin. Once you have defined a terminable middleware, you should add it to the list of route or global middleware in the app/Http/Kernel.php file. When calling the terminate method on your middleware, Laravel will resolve a fresh instance of the middleware from the service container.

Route [admin.categories.index] not defined., I have a named route and I'm getting an error that there's no route with that name. The error I'm getting is: Route [home] not defined. Here is the route in web.php: In laravel 5.4 it throws error: Attribute [controllers] does not exist. I really like the functionality Route::controllers provided so I could have functions like: getProjects, postProjects I wonder if there is something similar in 5.4. Thanks in advance.

Comments
  • You have posted code of all those which are already working and does not have any problem but you did not posted code for HotelReviewController...and what is the link that you have written to open up the create page?
  • I have removed HotelReviewController part now the situation is that I am on viewpost page. then after clicking a button I want to go to createhotel page.
  • Okay now create a method called create() in your HotelController and create a route to point that method. and I assume that you dont wanna got to external route right ('travelapp.me/hotel/viewpost/createhotel)...what is this 'travelapp.me/hotel/viewpost/createhotel
  • remove travelapp.me if you wanna use 'HotelPostsController@createhotel', and just point your link to /hotel/viewpost/createhotel....see my post below
  • I thought I had to add the complete route so I added this.travelapp.me/hotel/viewpost/createhotel
  • It is now giving error Trying to get property 'image' of non-object (View: \htdocs\travelapp\resources\views\hotel\viewpost.blade.php)
  • Wht it is trying giving error for image that I used in viewpost. although the url changed to http://travelapp.me/hotel/viewpost/createhotel
  • yeah URL will be changed automatically, when you place your image on HTML file use fill path like <img src="{{url('/img/img.1')}}"> or <img src="{{asset('/img/img.1')}}">
  • But I am getting image from db and accessing it thorugh php var
  • bud thank you very much it finally works thank you thank you so much
  • can you please elaborate. I am a little confuse.
  • You have a button: <button href="{{ route('/createhotel') }}" type="button" class="btn btn-default">Left</button> The route method you are using is expecting a named route. You are passing in the url of the route, not the name. Good news, you already have the name defined: Route::get('/hotel/create', 'HotelReviewController@create')->name('create'); So use the name 'create' in the route. Or use a different method, url('the/actual/route/here').
  • Ok i did it. the error is gone but it still won't go to the page. i.e. createhotel
  • http://travelapp.me/hotel/viewpost/1 this is the link when I am on viewpost page. so in Route do I have to add hotel/viewpost/1/createhotel or not?
  • I think you are confusing yourself by having routes that are very similar. It's confusing me too. I told you about the named route that points to HotelReviewController@create, but I think you're wanting to hit HotelPostsController@createhotel. You would need to give this route a name and change what I told you to match that new name. Your names can be more clean too, like hotel.create. Also, this is a hotel post, so why is the method createHotel? I think just 'create' is fine. Then it could return a view hotels.posts.create, with that folder structure. Just my opinion there though.