Angular remove values from Laravel form - php

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

Related

Update the user

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');
)};

Form model binding isn't working inside section

Parent blade template:
#extends('layouts.master')
#section('content')
<div class="panel-body">
#if(count($errors))
#include('common.errors')
#endif
{!! Form::model($entry, ['method' => $method, 'class' => 'form-horizontal', 'route' => [$route]]) !!}
#section('fields')
#foreach (['title', 'url', 'content', 'meta_tags', 'meta_description', 'is_active'] as $field)
#include('entries.fields.' . $field)
#endforeach
#show
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
#section('submit')
{!! Form::submit('Добавить', ['class' => 'btn btn-default']) !!}
#show
</div>
</div>
{!! Form::close() !!}
</div>
#endsection
Child template:
#extends('entries.create')
#section('title')
Добавить статью / {{ config('site.site_name') }}
#endsection
#section('fields')
#foreach ([
'entries.fields.title',
'entries.fields.url',
'articles.fields.description',
'entries.fields.content',
'entries.fields.meta_description',
'entries.fields.is_active',
'articles.fields.enable_comments',
'articles.fields.show_on_main',
'articles.fields.rank',
] as $field)
#include($field)
#endforeach
#endsection
Model binding works for parent template, but doesn't work in child template.
For example, I have enable_comments checkbox:
{!! Form::label('enable_comments', 'Включить комментарии', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::checkbox('enable_comments', null, null, ['class' => 'checkbox']) !!}
</div>
</div>
And it is always unchecked, while the $entry->enable_comments === true
I don't know why this is happening. Maybe anyone can go through the code and find the problem.
Thanks in advance for your help.
The problem is that form model binding works only inside the current template (with included files), but doesn't fill the values in child temlates. So the only solution is to write form start ( {!! Form::model(... )again, in the child template

laravel5 view with a starnge error

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.

Laravel MethodNotAllowedHttpException is being thrown

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']) !!}

display checked values on another page in laravel

I am new at Laravel. I am building a code that displays the records that have been checked.
Following is my code.
{!! Form::open(array('action' => 'ClientsController#store','method' => 'POST', 'name' => 'f1'))!!}
#foreach($clients as $client)
{!! Form::checkbox('agree', $client->email, null, ['class' =>'questionCheckBox']) !!}
<article>
{{ $client->user_name }}
{{ $client->email }}
</article>
#endforeach
{!! Form::close() !!}
{!! Form::open(array('action' => 'ClientsController#display','method' => 'GET'))!!}
<div class="form-group">
{!! Form::submit('show-selected ',['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
I have to display $client->email when I click button "show-selected".
My controller method is,
public function display() {
$client = Client::all();
dd(Input::has('agree'));
$client = Input::has('agree') ? true : false;
return $client->email;
}
This should return true, but it is returning false, I am not getting how to get the values of checked check boxes on another page.
This Worked.
My blade file is:
{!! Form::open(array('action' => 'ClientsController#display','method' => 'GET'))!!}
<div class="form-group">
{!! Form::checkbox("agree[]", 'email_1', null) !!} <p>email_1</p>
</div>
<div class="form-group">
{!! Form::checkbox("agree[]", 'email_2', null) !!} <p>email_2</p>
</div>
<div class="form-group">
{!! Form::checkbox("agree[]", 'email_3', null) !!} <p>email_3</p>
</div>
<div class="form-group">
{!! Form::submit('Show-Selected',['class' => 'btn']) !!}
</div>
{!! Form::close() !!}
And the display method is:
public function display(){
$data = Input::get('agree');
$count = count ($data);
echo "Selected email is/are:" . $count;
echo "<br/>";
foreach ($data as $big_name){
echo $big_name;
echo "<br/>";
}
}
After clicking button "Show-selected",the value of checked check-boxes will display.

Categories