laravel having problem with show method of laravel - php

i have a property model and i want to get the property show method and do some operation on it so i am on the show method right now consider the link below :
http://localhost:8000/properties/1
now from this link i submit a form to the route below :
Route::post('/properties/startreserve','PropertyController#startreserve');
and this is the controller of my startreserve and here i want to get the property that i had in last page which means property number 1 in this example exacly like show method :
public function startreserve(Request $request,Property $property){
.
.
.
return view('users.properties.reserve')
->with('property',$property);
}
now when i pass $property its empty but i want to do it as the show method !!!
ok now for example i want to pass the id 1 property and make the link look like this :
http://localhost:8000/properties/startreserve/1
and here is my view code :
<form class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed"
action="/properties/startreserve" method="post">
{{ csrf_field() }}
#if ($errors->any())
<div class="panel panel-flat bg-danger">
<div class="panel-heading">
<h5 class="panel-title"></h5>
<div class="heading-elements">
<ul class="icons-list">
<li><a data-action="close"></a></li>
</ul>
</div>
</div>
<div class="panel-body">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
</div>
#endif
<div class="row">
#foreach($pdate as $index => $pdates)
<div id="checkboxes" class="col-lg-2 text-center">
<input type="checkbox" name="d[{{$index}}]"value="{{verta($pdates->date)->format('Y/m/d')}}-{{$pdates->price}}" id="d{{$index}}"/>
<label class="whatever mt-3" for="d{{$index}}"> {{verta($pdates->date)->format('Y/m/d')}}
<hr>
{{$pdates->price}}</label>
</div>
#endforeach
<div class="col-lg-12">
<input type="submit" value="send" class="btn btn-primary">
</div>
</div>
</form>

You need to define the id on the route itself, as the route you have is not accepting the id.
Route::post('/properties/startreserve/{property}','PropertyController#startreserve');
So using a post request, you should be passing the ID in your action, you are missing that here.
<form class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed"
action="/properties/startreserve/{{$property->id}}" method="post">

Related

Lists in validation Laravel

I am doing a validation of a form in Laravel.
In this form I have two inputs (one text and one checkbox).
But I have two lists, in which I can move the elements from one list to another and order them.
But I don't know how to send these lists through the form to the Laravel validation.
Thanks in advance
My form:
<form id="create-menu-opac" action="{{ route('post_create_menu_opac')}}" method="post" role="form" autocomplete="off">
{{ csrf_field() }}
...
<section>
<div class="row">
<div class="col-sm-6">
<h6>{{ trans('menu-opac.buttons_avaiable') }}</h6>
<ul id="buttons_no_selected" class="list-group list-group-sortable-connected connected">
#foreach ($buttons as $button)
<li id="{{$button->id}}" class="list-group-item list-group-item-info">{{$button->description}}</li>
#endforeach
</ul>
</div>
<div class="col-sm-6">
<h6>{{ trans('menu-opac.items_menu') }}</h6>
<ul id="buttons_selected" class="list-group list-group-sortable-connected connected">
</ul>
</div>
</div>
</section>
...
</form>
This two lists work with a library Jquery and Boostrap
My controller
foreach ($request as $_request) {
Log::Debug(print_r($_request,true));
}
In this Log I can see the two inputs (type text and type checkbox), but i can't see the list.
Try adding input hidden in your blade file then see if you get the data in your $request
#foreach ($buttons as $button)
<li id="{{$button->id}}" class="list-group-item list-group-item-info">{{$button->description}}</li>
<input type="hidden" id="{{$button->id}}" value="{{$button->description}}" name="{{$button->description}}">
#endforeach

Data retrieving issue in Laravel

I'm trying display some data in my blade. Following is my current code for the controller's(ActivateController.php) index function,
public function index($id)
{
//echo $id;
$datas = Website::WHERE('appId','=',$id);
//dd($datas);
return view('activities.index',compact('datas','id'));
}
And my view url is something like,
TEST.site/activities/index/12
this is my blade, index.blade.php
#extends('layouts.admin')
#section('content')
<div class="container">
<div class="row">
<div class="col-sm">
<div class="pull-left">
<h2 class="mt-2">Activate Website</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('websites.index') }}"> Back</a>
</div>
</div>
</div>
</div>
#if (count($errors) > 0)
<div class="container ">
<div class="row">
<div class="col-sm">
<div class="alert alert-danger mt-2">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
</div>
</div>
</div>
#endif
<div class="container mt-3">
<div class="row">
<div class="col-sm">
#foreach ($datas as $object)
<form id="w1" action="{{ route('activities.update',$object->appId) }}" method="POST">
#csrf
#method('PUT')
<strong>Select Package Type:<span class="star">*</span></strong>
<input type="text" name="app_domain" value="{{$object->domain}}">
<strong>Select Package Type:<span class="star">*</span></strong>
<select id="app-packagetype" class="form-control" name="package_type" aria-required="true">
<option value="{{$object->payment_option }}">{{$object->payment_option }}</option>
<option value="monthly">Monthly [12]</option>
<option value="yearly">Yearly [99]</option>
</select>
<br>
<div class="form-group text-right">
<button type="submit" class="btn btn-success">{{ __('Activate') }}</button>
</div>
</form>
#endforeach
</div>
</div>
</div>
#endsection
But now my issue is , when I try to retrieve the data,
{{$object->appId}}
It retrieves empty....
Where I'm doing wrong and how to retrieve the data properly to the view?
you are missing get() at the end
change this:
$datas = Website::where('appId','=',$id);
to
$datas = Website::where('appId','=',$id)->get();
Thanks..
You use just like this
$datas = Website::where('appId',$id)->get();

How to bind a route url for form tag in laravel

This is my form tag
<form method="POST" action="{{ url("/post/{$article->id}/comment") }}">>
This is my route
Route::post('/post/{article}/comment', 'CommentController#store');
This is my commentcontroller method
public function store(Article $article)
{
$comment = $article->comment->create([
'body' => request('body'),
]);
return back();
}
show.blade.php
`#extends('master')
#section('content')
<!-- Example row of columns -->
<div class="container">
<h1> {{ $articles->title }} </h1>
<p> {{ $articles->body }} </p>
<hr></hr>
<div class="comment">
<ul class="list-group">
#foreach($articles->comments as $comment)
<li class="list-group-item">
<strong>
{{ $comment->created_at->diffForHumans()}} :
</strong>
{{ $comment->body }}
</li>
#endforeach
</ul>
</div>
<!-- Here is comment form -->
<hr>
<div class="card">
<div class="card-block">
<form method="POST" action="{{ url ("/post/{$article->id}/comment") }}">>
{{ csrf_field() }}
<div class="form-group">
<textarea name="body" placeholder="your comment here." class="form-control"> </textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Add Comment</button>
</div>
</form>
</div>
#include('partials.errors')
</div>
</div>
#endsection`
When I'm trying to add comment on article I'm getting an error like this:
> Undefined variable: article (View: C:\xampp7\htdocs\Lara\resources\views\article\show.blade.php)
Anything wrong in this? help me out. Thanks in advance
It seems you are not passing $article to view. You haven't included the code but you have somewhere something like this:
return view('article.show');
and instead you should have:
return view('article.show', compact('article'));
so finally your show method in controller should look something like this:
public function show(Article $article)
{
return view('article.show', compact('article'));
}
Its because you are calling your article $articles (plural) when in fact it is a single article.
in your controller change $articles to $article and then change it in the view where you have articles, for instance $articles->body. It will then be correct when you use it in the form action.

MethodNotAllowedHttpException not found when I paginate in Laravel

Hello this is my first question here.
I am using php laravel framework and I am getting this error
MethodNotAllowedHttpException in RouteCollection.php line 233:
This error comes when I go to second page of the result list.
My controller code.
public function find_product(Request $request)
{
$search = trim($request->product);
$products = Store_product::(query-for-products-working)
->paginate(1);
return view('fc.product',compact('products','search'));
}
My web.php code
Route::post('/product', 'FlashCartController#find_product');
My view code
#foreach($products as $product)
<div class="fc-col">
<div class="panel panel-primary">
<div class="panel-heading fc-col-head"><div class="marquee">{{ $product->product_name }}</div></div>
<div class="panel-body fc-col-body">
<img src="{{ image_check('uploads/store/products/',$product->product_image1,'uploads/service/') }}" class="img-responsive" style="width:100%; height: 100%;" alt="{{ $product->product_name }}" />
</div>
<div class="panel-footer fc-col-footer">
<span class="price">Rs.
{{
price_check($product->product_discount, $product->product_price, $product->sale_id, $product->discount)
}}/-
</span>
</div>
</div>
</div>
#endforeach
<div>
{{ $products->links() }}
</div>
and the form
<form action="/product" method="POST">
{{ csrf_field() }}
<div class="input-group container">
<input type="text" name="product" class="form-control" value="{{$search}}" placeholder="Enter product name" />
<div class="input-group-btn">
<input type="submit" class="btn btn-danger" value="Search" />
</div>
</div>
</form>
Why my method is not allowed. And if this is not the method to use what should I do?
Can anyone help me with this please? :(
Okay so your problem as I understand it is that when you paginate to the next page the url becomes empty and no results are shown.
In your view you have this line:
{{ $products->links() }}
Which shows that whatever your url is at the moment, just ignore it and add pagination to it.
That means if your url is like www.abc.com?product=graphics it will ignore product and only add www.abc.com?page=1,2,... Of course your page will be blank.
Instead use this:
{{ $products->appends(request()->input())->links() }}
Now it tells the system to add pagination but append variables to it too. What variables? The variables that are appended on the url already.
Hope it helps

No query results for model [App\Card]

I have the following problem:
No query results for model [App\Card].
My Route.php:
Route::post('/cards/{card}/notes' , 'NotesController#store');
My NotesController:
public function store(Request $request)
{
return $request->all();
}
And my View:
#section('content')
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1> {{ $card->title }}</h1>
<h4> {{ $card->created_at }}</h4>
<ul class="list-group">
#foreach($card->notes as $note)
<li class="list-group-item">{{ $note->body }}</li>
#endforeach
</ul>
<hr>
<h3>Add a New Note</h3>
<form action="post" action="/cards/{{ $card->id }}/notes">
<div class="form-group">
<textarea name="body" class="form-control"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Add note</button>
</div>
</form>
</div>
</div>
#stop
I have two database tables - cards and notes.
This is my route.php
Route::get('/' , 'PagesController#home');
Route::get('/about' , 'PagesController#about');
Route::get('cards' , 'CardsController#index');
Route::get('cards/{card}' , 'CardsController#show');
Route::post('/cards/{card}/notes' , 'NotesController#store');
Yes i have records in tables here is pics
cards
Notes

Categories