I have a web form in Laravel that is behind an ip. Example:
127.0.0.1/posts/create
With a simple form helper:
{{ Form::open(array('url' => '/posts','files'=>'true')) }}
#include('posts._form')
{!! Form::submit('Create Post', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
When I inspect the html, https is added to the url. How can I stop this?
Found the problem, my nginx had the HTTPS variable set on. Laravel apparently reads that variables and adds the protocol + host_name to all redirect actions.
Related
I have this form in blade:
{{ Form::open(['action' => ['SearchController#searchUser'], 'method' => 'GET']) }}
{{ Form::text('q', '', ['id' => 'q', 'placeholder' => 'Enter name'])}}
{{ Form::submit('Search', array('class' => 'button expand')) }}
{{ Form::close() }}
How can I translate it into html?
If you're using Laravel 5.2, you must install HTML and Form as module.
follow these steps and it must be rendered your code:
https://laravelcollective.com/docs/5.2/html
If you are new to Laravel and feel its confusing with all those syntax you can use normal HTML that you already know. Its not a compulsion to use Laravel's blade shortcut.So something like
<form action="SearchController#searchUser" method="get">
//All your inputs
</form>
And to use form in your project you have to get a facade. You can follow the tutorial below :
http://www.easylaravelbook.com/blog/2015/02/09/creating-a-contact-form-in-laravel-5-using-the-form-request-feature/
I use Laravel 5 and try to update a form:
{!! Form::model($user, ['route' => ['edit', $user->id], 'method' => 'PUT']) !!}
{!! Form::label('titel', 'First Name:'!!}
{!! Form::text('titel', null,) !!}
<button type="submit">Update</button>
{!! Form::close() !!}
My route:
Route::post('edit/{id}', ['as' => 'edit', 'uses' => 'UserController#editUser']);
My controller:
public function editUser($id){};
When click on the update Button I get MethodNotAllowedHttpException in RouteCollection.php
I checked in the browser source code and saw that Form::model(..) which I use generate the following output:
<form method="POST" action="http://localhost/myProject/public/edit/1" accept-charset="UTF-8"><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="4nZlyfzzAZmTcZfThQ8gcR6cgEgYgR0ip0JZTKck">
Within the form there is the attribute method="POST" and the hidden input has the attribute value="PUT". This seems not correct for me. Any ideas? Thank you
You should use 'update' route to actually save the data (validate and persist it to the database). 'edit' route is what you used to generate edit form.
You should use PUT method to run method which saves data.
Also, here is small tip for you. Learn about how RESTful controllers work. They are really easy way to do what you're doing here (defenetly worth to learn them):
https://laravel.com/docs/5.1/controllers
Your route is not the same as your form.
Laravel uses the hidden inputs to specify the different http methods, as put.
So in your routes you should use a put method not a post.
Route::put();
I have the following delete button:
{!! Form::open(['route' => ['tasks.destroy', $type->id], 'method' => 'delete']) !!}
{!! Form::submit('Erase this task?', ['class' => 'delete']) !!}
{!!Form::close() !!}
And now I would like to not use a button, but an icon to delete content. I would like to use this button: http://fortawesome.github.io/Font-Awesome/3.2.1/icon/remove-sign/
<i class="icon-remove-sign"></i> icon-remove-sign
The sign should be blue and small.
How do I do that? I only get error messages relating to models as a result. But when I dont make any changes it works perfectly.
Can someone give me an example of how to make the picture point to a delete route?
The form helper does not allow you to add HTML to it. Use a simple HTML button:
{!! Form::open(['route' => ['tasks.destroy', $type->id], 'method' => 'delete']) !!}
<button class="delete">
<i class="icon-remove-sign"></i> Erase this task
</button>
{!!Form::close() !!}
I am having trouble linking my stylesheets, scripts, and images for a non-base route in my Laravel 5 app. When I access example.com/about the scripts and stylesheets are working correctly but if I access example.com/about/something the scripts and stylesheets link to example.com/about/css/style.css rather than example.com/css/style.css
My code is as follows:
Routes.php:
Route::get('about/{slug?}', ['as' => 'officerProfile', 'uses' => 'PagesController#about']);
PagesController.php:
public function about($slug = 'president')
{
$officers = Officer::all();
$currentOfficer = Officer::where('slug', $slug)->first();
return view("pages.about", ['title' => $this->makeTitle('Learn About Us')])->with('officers', $officers)->with('currentOfficer', $currentOfficer);
}
layout.blade.php:
{!! HTML::script('https://code.jquery.com/jquery-2.1.4.min.js') !!}
{!! HTML::script('js/skel.min.js') !!}
{!! HTML::script('js/skel-layers.min.js') !!}
{!! HTML::script('js/init.js') !!}
{!! HTML::script('js/scripts.js') !!}
<noscript>
{!! HTML::style('css/skel.css') !!}
{!! HTML::style('css/style.css') !!}
{!! HTML::style('css/style-desktop.css') !!}
</noscript>
For some reason Laravel is thinking the base URL is example.com/about when the loaded route is example.com/about/something. I have tried as well but it still routes to example.com/about/images/image.jpg rather than example.com/images/image.jpg. Any advice would be greatly appreciated. Thank you!
You are using relative paths and you need absolute paths. See the example below, the only thing I added is the prepended /
{!! HTML::script('https://code.jquery.com/jquery-2.1.4.min.js') !!}
{!! HTML::script('/js/skel.min.js') !!}
{!! HTML::script('/js/skel-layers.min.js') !!}
{!! HTML::script('/js/init.js') !!}
{!! HTML::script('/js/scripts.js') !!}
<noscript>
{!! HTML::style('/css/skel.css') !!}
{!! HTML::style('/css/style.css') !!}
{!! HTML::style('/css/style-desktop.css') !!}
</noscript>
A relative path loads files related to the current path. Eg from the page http://example.com/about/us you can relatively load images/logo.png which results in the actual request to http://example.com/about/images/logo.png.
An absolute path is always from the hostname: same example as above but you'd load /images/logo.png which results in http://example.com/images/logo.png
1st question:
I've inserted the localization in many types of texts and things, but I don't know how to import it into in the following forms:
{{ Form::label('name', 'here') }}
{{ Form::text('name', null, array('placeholder' => 'here')) }}
{{ Form::submit('here', array('class' => 'btn btn-success')) }}
{{ Form::button('here', array('class' => 'btn btn-default')) }}
I want it to be in the form label 'here' and in the placeholder of the text 'here'.
2nd question:
I am not allowed to insert it with links in my language file: text here blah blah BLAH?
Is there anyway to insert it with links?
Thanks in advance.
Supposing that your messages are stored in app/lang/en/message.php you can use the same way for all your cases:
In Blade template:
{{ Form::label('name', Lang::get('message.key')) }}
{{ Form::text('name', null, array('placeholder' => Lang::get('message.key'))) }}
{{ Form::submit(Lang::get('message.key'), array('class' => 'btn btn-success')) }}
In HTML tag mixed with some Blade expression:
BLAH
You can also use localization in Blade templates using strictly Blade syntax.
Given that you have a message in your /app/lang/en/messages.php that corresponds to the key "message_key", you can do :
#lang('messages.message_key')
to render the message in the locale that your application is configured to use.
So, The answers for both of your questions are:-
1) {{ Form::label('name', 'here') }}
Here, you need to change the "here" text hence laravel localization method can be used.For eg:-
{{ Form::label('name', '__("Here")' }} or
{{ Form::label('name', '__('message.here') }}.
2)< a href="{{ URL::to('text') }}">BLAH< /a>
Here, you need to change the label instead of link.
< a href="URL::to('text') ">{{__('message.BLAH')}}< /a>.
This is the simplest which works for me !
{!! Form::label('title', trans('users.addNewRecordsNameFieldLabel'),['class' => 'control-label']) !!}
I feel, already blade parsing is started the moment {!! or {{ is started
A possible answer to your second question:
You could set up a language file resources/lang/en/page.php like this:
return [
'sentence' => 'A sentence with a :link in the middle.',
'link_text' => 'link to a another page'
];
And use it in a Blade template like this:
{!! trans('page.sentence', [
'link' => '' . trans('page.link_text') . ''
]) !!}}
The result would be:
A sentence with a link to a another page in the middle.
You alse can use __() method
{{ __('app.name') }}