i have this view and when i request it it shows me a strange error, well strange for me i guess.
my create.blade.php
#extends('layouts.app')
#section('content')
<div class="col-md-6">
{!! Form::open([action('PropertiesController#update', $property->id), 'files'=>true]) !!}
<div class="form-group">
{!! From::label('category', 'category') !!}
{!! Form::select('category', {{ $categories }},['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('city', 'located city') !!}
{!! Form::select('city', {{ $citys }},['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('street', 'Street adress: ') !!}
{!! Form::text('street', 'Adress', ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::file('images') !!}
</div>
<div class="form-group">
{!! Form::label('description', 'Add description') !!}
{!! Form::textarea('description', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Done', ['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
#stop
the error is:
ErrorException in 83c90d4b665ecd8385b3b6b2e7203d1ef06a1339.php line 8:
Parse error: syntax error, unexpected '<' (View:
/home/vagrant/Code/housing/resources/views/properties/create_property.blade.php)
please help am stuck :(
You are trying to use blade syntax within blade syntax, which you don't need to do.
{!! Form::select('category', {{ $categories }},['class'=>'form-control']) !!}
It can simply be
{!! Form::select('category', $categories, ['class'=>'form-control']) !!}
You've done it in a couple locations, so make sure to fix them all up. You'll notice the error mentions line 8, which is the line immediately after this error occurs.
Related
I want to update the user using this Form:
{!! Form::model($user ,['method'=>'PATCH', 'action'=>['AdminController#update',$user->id], 'files'=>true]) !!}
<div class="form-group">
{!! Form::label('first_name','First Name:') !!}
{!! Form::text('first_name',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('last_name','Last Name:') !!}
{!! Form::text('last_name',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('username','Username (Student ID):') !!}
{!! Form::number('username',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('email','Email:') !!}
{!! Form::email('email',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('address','Address:') !!}
{!! Form::text('address','null',['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('phone_number','Phone Number:') !!}
{!! Form::number('phone_number','null',['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('password','Password:') !!}
{!! Form::password('password',['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Update User', ['class'=>'btn btn-primary col-sm-6']) !!}
</div>
{!! Form::close() !!}
and this is my Route:
Route::prefix('admin')->group(function(){
Route::post('/users/{id}','AdminController#update');
)};
when I press update button I receive this error:
Please help me, I am Using Laravel 5.4
try following
{{ Form::model($user, array('route' => array('users.update', $user->id), 'method' => 'PUT')) }}
// form fiedls come here
{!! Form::close() !!}
in route file add following route:
Route::resource('users', "UserController");
and in user controller add following code:
public function update(Request $request, $id){
// Add form validation here
$user = User::find($id);
$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->save();
Session::Flash('success', 'The User have been updated successfully!');
return redirect()->route('users.index');
}
don't user AdminController to manage users.
Please use PATCH in routes for example :
Route::patch('/users/{id}','AdminController#update');
your method is post , but you send patch request
you should change to this
'method'=>'post'
you can use this code to fix every thing
form blade
{{ Form::model($user, array('route' => array('update-user', $user->id), 'method' => 'PUT')) }}
route
Route::prefix('admin')->group(function(){
Route::PUT('/users/{id}','AdminController#update')->name('update-user');
)};
I am having a issue with Laravel 5.2 accessing the $errors variable in my partial.
routes.php
I have wrapped my routes in the middleware web.
and in my auth.blade.php
<div class="col-md-4">
<div class="panel panel-{{ $errors->all() ? 'danger' : 'default'}}">
<div class="panel-heading">
`enter code here`<h2 class="panel-title">#yield('heading')</h2>
</div>
<div class="panel-body">
#if($errors->all())
<div class="alert alert-danger">
<strong>We found some errors</strong>
<ul>
#foreach($errors->all() as $errors)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
#yield('content')
</div>
</div>
</div>
here is the code for my login partial
#extends('layouts.auth')
#section('title','Login')
#section('heading','Welcome Please login')
#section('content')
{!! Form::open() !!}
<div class="form-group">
{!! Form::label('email') !!}
{!! Form::text('email', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('password') !!}
{!! Form::password('password', ['class' => 'form-control']) !!}
</div>
{!! Form::submit('Login', ['class' => 'btn btn-primary']) !!}
Forgot password?
{!! Form::close() !!}
#endsection
when i click login it just redirects to the same page buit not flashing the errors?
When i click login it shows this error
enter image description here
Remove web middleware, this may cause empty $errors. Since 5.2.27, web middleware aplies automatically to all routes and you shouldn't add it again manually.
I am watching a Laracast on forms, and my code is quite basic, and yet so is my knowledge of the framework. My code is below, and what your looking at, if you haven't taken a guess, is that I wish to create a list of values to be stored in a database, and to "Redirect" the user to there newly stored values. The "store" part seems to be the area of issue. Whenever I click "add food items" I am not redirected, yet this error appears, MethodNotAllowedHttpException.
Route::get('food/create', 'FoodController#create');
Route::post('fond/post', 'FoodController#store');
Route::get('food/{id}', 'FoodController#index');
namespace App\Http\Controllers;
use App\Food;
use Illuminate\Http\Request;
class FoodController extends Controller
{
public function index($id)
{
$food = Food::find($id);
return view('index')->with('food', $food);
}
public function create()
{
return view('vendor.create');
}
public function store(Request $request)
{
$input = Request::all();
$food = Food::create($input);
return redirect('food/'.$food->id);
}
}
#extends('app')
#section('body')
<h1>Foods!</h1>
<h2>{{ $food->vegetables }}</h2>
<h2>{{ $food->fruit }}</h2>
<h2>{{ $food->grains }}</h2>
<h2>{{ $food->meat }}</h2>
<h2>{{ $food->sugar }}</h2>
#stop('body')
#extends('app')
#section('body')
{!! Form::open(['url'=>'food/store']) !!}
<div class="form-group">
{!! Form::label('vegetables', 'Vegetable item:') !!}
{!! Form::text('vegetables', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('fruit', 'Fruit item:') !!}
{!! Form::text('fruit', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('meat', 'Meat item:') !!}
{!! Form::text('meat', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('grains', 'Grain item:') !!}
{!! Form::text('grains', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('sugar', 'Sugar item:') !!}
{!! Form::text('sugar', null, ['class' => 'form-control']) !!}
</div>
<div>
{!! Form::submit('Add Food items', ['class' => 'btn btn-primary form-control']) !!}
{!! Form::close() !!}
</div>
#stop('body')
Add the get method in you form opening tag. It should look like this:
{!! Form::open(['url'=>'food/store','method'=>'get']) !!}
I have two models: Category and CategoryValue.
Inside my Category model I have:
public function values()
{
return $this->hasMany('App\CategoryValue');
}
Inside my CategoryValue I have:
function category()
{
return $this->belongsTo('App\Category');
}
In my edit view, I have my form model binding like so:
{!! Form::model($category, ['route' => ['category.update', $category->slug], 'method' => 'PATCH']) !!}
#include('partials.categoryForm')
{!! Form::close() !!}
Where $category is a chosen Category Model.
The categoryForm partial looks like:
<div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
{!! Form::label('name', 'Name') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
{!! $errors->first('name', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group {{ $errors->has('slug') ? 'has-error' : '' }}">
{!! Form::label('slug', 'Slug') !!}
{!! Form::text('slug', null, ['class' => 'form-control']) !!}
{!! $errors->first('slug', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group">
{!! Form::submit('Save Page', ['class' => 'btn btn-primary']) !!}
</div>
That's all working, but when editing the Category, I'd like to be able to edit (add/remove) associate CategoryValues. To start, I want the items returned from $category->values to be inside a textarea with each CategoryValue on a new line.
I can think of a couple of ways to do this: use a #foreach and generate the textarea, or popular a variable and use that in the binding. I'm not sure which of these, if either, is the "Laravel" way to do it. I'm also not sure if either of those can be used to update the records in the DB properly. How should this be done?
I have a angular module named shop and controller named CartCtrl:
angular.module('shop').controller('CartCtrl', function($scope, $http, ngCart) {
$scope.order_name = null;
$scope.order_phone = null;
});
In template i have:
<div class="modal-body" ng-module="shop" ng-controller="CartCtrl">
{!! Form::model(Auth::user()->profile, [ 'route' => 'order.send'], [ 'id'=>'order_form']) !!}
<div class="form-group">
{!! Form::text('name', old('name'), ['class'=>'form-control', 'placeholder'=>'Ваше имя', 'ng-model'=>'order_name']) !!}
</div>
<div class="form-group">
{!! Form::text('phone', old('phone'), ['class'=>'form-control', 'placeholder'=>'Ваш телефон', 'ng-model'=>'order_phone']) !!}
</div>
{!! Form::close() !!}
</div>
But when I go to the page and look at the form, then it is empty. But if I take away: ng-module="shop" ng-controller="CartCtrl" all will be ok. Why is that?
UPD:
If i remove ng-model it will be the same, values in inputs has will be empty