Friday, May 4, 2018

Route [/createhotel] not defined. laravel 5.4 - development

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">&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/"><img class = "img__img" src= alt="Logo" style="width:90%;height:90%" ></a>
    <p class = "img__description">  <br> <br> </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 AppHttpControllers;

use IlluminateHttpRequest;

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= alt="Image" style="width:100%">
  <div class="container">
    <h4><b></b></h4> 
    <p>Rating: <br>Price: </p> 
  </div>
</div>

 <button href="" type="button" class="btn btn-default">Left</button>
</div>

<h2>Reviews</h2>

@foreach ($reviews as $review)
    <p><br></p>
    <br><br><br>

@endforeach

@endsection

</body>
</html>

This is controller for my viewpost:

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

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');
Auth::routes();

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

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.



from Laravel Questions and Answers https://laravelquestions.com/laravel/route-createhotel-not-defined-laravel-5-4/
via Lzo Media

No comments:

Post a Comment