The problem is i want to skip that edit page. it works as fine. but i wanna edit my data in index view.
i tried this but i took this error
{!! Form::model($choice, ['method' => 'PATCH','route' => ['choices.update', $choice->id]]) !!}
<input class="form-control" value="#foreach ($choices as $choice){{ $choice->question_number }}#endforeach" type="number" name="number"></input>
{!! Form::submit('Update Task', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
Trying to get property of non-object (View: C:\wamp64\www\zainsurgalt\resources\views\choices\index.blade.php)
index view
<td>Edit</td>
edit view
{!! Form::model($choice, ['method' => 'PATCH','route' => ['choices.update', $choice->id]]) !!}
<input class="form-control" type="number" name="number"></input>
{!! Form::submit('Update Task', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
controller update
public function update(Request $request,Choice $choice){
Choice::where('id', $choice->id)->update([
'question_number' => $request->input('number')
]);
return redirect()->route('choices.index');
}
All time when you get object property you must be check object exist or not
#if (!empty($duplicate->topic))
<td>Edit</td>
#endIf
also
#if (!empty($choice))
{!! Form::model($choice, ['method' => 'PATCH','route' => ['choices.update', $choice->id]]) !!}
<input class="form-control" type="number" name="number"></input>
{!! Form::submit('Update Task', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
#endIf
and finally you use
#foreach ($choices as $choice){{ $choice->question_number }}#endforeach
change $choice to another name for example $_choice , for not confusing above used $choice
Related
I have a form in Laravel. I want to change the width of the form, because I want to put a other form next to it.
It looks like this
Which codes I should use in app.css? Any Suggestions? I tried codes in app.css but, maybe I should give a ID to form?
{!! Form::open(['method' => 'POST', 'action' => 'BusinessController#buy_energy']) !!}
<img src="images/foods/1.png" width="80px" height="80px"><br>
{!! Form::label('number', 'Ekmek(1 adt = 7 TL): ') !!}
{!! Form::number('number', 'value', ['min'=>1, 'max'=>10 ]) !!}
{!! Form::submit('Satın Al', ['class'=>'btn btn-primary']) !!}
In your blade add in the form the 'class' just like you add the action and the method:
{!! Form::open(['method' => 'POST', 'action' => 'BusinessController#buy_energy', 'class' => 'myForm']) !!}
<img src="images/foods/1.png" width="80px" height="80px"><br>
{!! Form::label('number', 'Ekmek(1 adt = 7 TL): ') !!}
{!! Form::number('number', 'value', ['min'=>1, 'max'=>10 ]) !!}
{!! Form::submit('Satın Al', ['class'=>'btn btn-primary']) !!}
In your Css customize the myForm class:
.myForm{
with: 400px;
}
I'm using LaravelCollective form to delete an employee:
{!! Form::open(['method' => 'DELETE', 'action' => ['EmployeesController#destroy', $employee->id, $company->id]]) !!}
<div class="form-group">
{!! Form::submit('Remove employee', ['class'=>'btn btn-danger']) !!}
</div>
{!! Form::close() !!}
and want to pass 2 arguments: employee id and company id.
My route:
Route::delete('/employees/{employee}/{company}', 'EmployeesController#destroy');
My controller function:
public function destroy($id, $companyId)
{
Employee::find($id)->delete();
if($companyId == 0)
return redirect('/employees');
else
return redirect('/companies/' . $companyId . "/edit");
}
I'm getting an error that I'm passing only 1 parameter. Where is the problem?
Try this instead:
// named route
Route::delete('employees/{employee_id}/{catetory_id}', 'EmployeesController#destroy')->name('employees.destroy');
// form using named route
{!! Form::open(['method' => 'DELETE', 'route' => ['employees.destroy', $employee->id, $company->id]]) !!}
<div class="form-group">
{!! Form::submit('Remove employee', ['class'=>'btn btn-danger']) !!}
</div>
{!! Form::close() !!}
You have to send the params in an array, try something like this.
{!! Form::open(['method' => 'DELETE', 'action' => ['EmployeesController#destroy', [$employee->id, $company->id] ]]) !!}
<div class="form-group">
{!! Form::submit('Remove employee', ['class'=>'btn btn-danger']) !!}
</div>
{!! Form::close() !!}
The variable name should match the route parameter. Try something like this in your controller:
public function destroy($employee, $company)
{
Employee::find($employee)->delete();
if($company == 0)
return redirect('/employees');
else
return redirect('/companies/' . $company . "/edit");
}
}
I am trying to check if the image that i am trying to upload is getthing processed, but when i try to use de Input::hasFile('upimg') to check it out it doesnt do anything. This is my form:
{!! Form::open(array('route' => array('uploadimage'), 'method' => 'POST')) !!}
{!! csrf_field() !!}
<div class="form-group">
{!! Form::label('newimg', 'Choose Image to upload:', ['class' => 'control-label']) !!}
{!! Form::file('upimg', null) !!}
</div>
<div class="form-group">
{!! Form::label('directory', 'Choose directory:', ['class' => 'control-label']) !!}
{!! Form::select('newimage', [ '' => 'none'] + $imagesdir , '', ['class' => 'form-control']) !!}
</div>
{!! Form::submit('Upload', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
And this is the code i am using to check the file:
public function doUpload()
{
if (Input::hasFile('upimg')){
echo 'uploaded';
};
}
As you can see i am trying to check:
{!! Form::file('upimg', null) !!}
If i am not wrong its suppose to give mi back the echo but nothing happens. Why is this not working? what am i doing wrong?
Be sure you have an 'file' => true option in your form definition like below:
{!! Form::open(['route' => ['uploadimage'], 'file' => true]) !!}
This option causes that your form will be render with enctype="multipart/form-data" option in HTML form tag. See documentation: HTML enctype
You don't have to add method => 'POST' to your definition of form, because Laravel 5 sents forms with POST method by default.
Please let me know if this solution will not work for you.
For checking files on server side you can use methods of Request object like in documentation of Laravel: Files in Laravel
I have this table that contains data from the database table 'patient'.
<td>
<a href="{{ URL::to('/addvisit/'.$patient->pID) }}">
<img src="images/visit.png" style="width:30px; height:30px;">
</a>
</td>
when the circle icon is clicked it will redirect to a page with a form that will be inserted in a database table 'visit'.
below is the form:
{!! Form::model($patient, ['url'=>'visit/' . $patient->pID, 'method' => 'PATCH']) !!}
<div class="form-group">
{!! Form::label('fname', 'Full Name',['class' => 'control-label'])!!}
{!! Form::text('pName',null,['class' => 'form-control']) !!}
{!! Form::label('address', 'Address',['class' => 'control-label'])!!}
{!! Form::text('pAddress',null, ['class' => 'form-control']) !!}
{!! Form::submit('SUBMIT',['class' => 'form-control btn btn-success']) !!}
</div>
{!! Form::close() !!}
how can I add the patient ID from the 'patient' table to be set as a foreign key in the 'visit' table.
Pass it again to the view with the form through controller and store it on a hidden input
I am thinking of making a landing page from the home page, which will direct the guest to the register page. I thought of making two forms for sending data and two submit buttons in them, let's say reader and writer and according to the button they use to go to the register form page, I want to pass the profession string from the button in the landing page and then, place it into the register form in /auth/register.
{!! Form::open(array('url' => '/auth/register', 'profession' => 'writer')) !!}
{!! Form::submit('Writer', array('class' => 'btn btn-warning')) !!}
{!! Form::close() !!}
{!! Form::open(array('url' => '/auth/register', 'profession' => 'reader')) !!}
{!! Form::submit('Reader', array('class' => 'btn btn-default')) !!}
{!! Form::close() !!}
It is not directing me to the page app.com/auth/register. But it works when I directly type the link.
What I thought was using $profession in /auth/register/ and access the value and use it as a hidden field in the registeration form.
(using laravel 5.1)
Edit:
In view source:
<form method="POST" action="http://app.com/auth/register" accept-charset="UTF-8" profession="writer"><input name="_token" type="hidden" value="dZXQsNI1BGQ39JjDLFUEkSQzL5bTNwe8o3rpiSQL">
<input class="btn btn-warning" type="submit" value="Writer">
</form>
<form method="POST" action="http://app.com/auth/register" accept-charset="UTF-8" profession="reader"><input name="_token" type="hidden" value="dZXQsNI1BGQ39JjDLFUEkSQzL5bTNwe8o3rpiSQL">
<input class="btn btn-default" type="submit" value="Reader">
</form>
Edit 2:
{!! Form::open(array('url' => '/auth/register', 'profession' => 'writer')) !!}
{!! link_to('/auth/register', 'Writer', array('class' => 'btn btn-default')) !!}
{!! Form::close() !!}
I tried this instead. At least, now it is directing the page but I still can't access the data value of profession
Edit 3:
Routes:
Route::get('auth/register', 'Auth\AuthController#getRegister');
Route::post('auth/register', 'Auth\AuthController#postRegister');
Route::get('/', function()
{
return view('pages.home');
});
and https://app.com/auth/register is working.
Here's a step by step walkthrough on how to implement it. I tested it. So it works. This is for 'writer', but you could replicate it as you had originally planned for other professions.
I assume you've registered the Laravel Collective package since you're using the curly braces and exclamation points.
Step 1:
In your landing page view, where you have the writer button, add a hidden field with the string 'writer'. Like this:
{!! Form::open(['route' => ['writer_path']]) !!}
{!! Form::hidden('profession', 'writer') !!}
{!! Form::submit('Writer', array('class' => 'btn btn-warning')) !!}
{!! Form::close() !!}
Not that in the open field we are using a named route ('writer_path').
Step 2:
Register a route and a controller on your routes.php file, like this:
Route::post('auth/register', [
'as' => 'writer_path',
'uses' => 'SampleController#displayForm'
]);
Step 3:
In your sample controller, you define the displayForm method.
Within that method you first obtain the value you passed from the landing page view.
If you don't know how to create a controler, you can do
php artisan make:controller SampleController
from the command line
Because the value arrives as an array, you have to obtain the string 'writer' from the array and then pass it to the new view (the view with the registration form for the writer).
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
class SampleController extends Controller
{
/**
* Display a listing of the resource.
*
* #return Response
*/
public function displayForm()
{
$input = Input::get();
$profession = $input['profession'];
return view('writerregistration', ['profession' => $profession]);
}
}
Last Step:
In the new view which you will create as writerregistration.blade.php, you will display the form with the field you just passed ('profession') which contains the string 'writer'. Like this:
{!! Form::open() !!}
{!! Form::label('username', 'Username:') !!}
{!! Form::text('username', null, ['class' => 'form-control']) !!}
{!! Form::label('profession', 'Profession:') !!}
{!! Form::text('profession', $profession, ['class' => 'form-control']) !!}
{!! Form::label('email', 'Email:') !!}
{!! Form::text('email', null, ['class' => 'form-control']) !!}
{!! Form::label('passowrd', 'Password:') !!}
{!! Form::password('password', ['class' => 'form-control']) !!}
{!! Form::label('password_confirmation', 'Password Confirmation:') !!}
{!! Form::password('password_confirmation', ['class' => 'form-control']) !!}
{!! Form::submit('Sign Up', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
Presto, you've populated the field in the registration form for the writer with the info on the hidden field that belonged to the writer button in the landing page.