#if statement using URL parameter laravel blade - if-statement

I am new to laravel and blade. I'm a student doing a simple 'job seeker' assignment. I have 2 different types of users - jobseekers (category 1) and employers (category 2). When I create a new user from buttons in layout.blade.php, users will click on a register (category 1) link or an Employer Button (category 2), I want to pass the category on to the create.blade.php so that I can stylise it depending on what category they are, and of course keep that information hidden from the actual User.
I'm not sure what code you want to see, but I'll start with my layout.blade.php - when the link or button is clicked, it redirects to create.blade.php and the url updates to either category 1 or categoy 2 - depending on what is clicked. I want to add an #if statement as to which create for gets displayed, one jobseeker or one for employer (they have slightly different options)
layout.blade.php
<div class="col-sm-9">
#if (!Auth::check())
<div class="login-form">
{{ Form::open(array('action' => 'UserController#login')); }}
{{ Form::text('username', null, array('class' => 'input-small', 'placeholder' => 'Email')); }}
{{ Form::password('password', array('class' => 'input-small', 'placeholder' => 'Password')); }}
{{ Form::submit('Sign in', array('class' => 'btn btn-danger')); }}
{{ Form::close(); }}
{{ Form::open(array('action' => 'UserController#create')); }}
{{link_to_route('user.create', 'or Register here', ['category' => 1] )}}
</div>
{{link_to_route('user.create', 'Employers', ['category' => 2], array('class' => 'btn btn-primary')) }}
#endif
#yield('content1')
create.blade.php
#extends('job.layout')
#section('content1')
#if('category' == 2)
<h1>New Employer page</h1>
{{ Form::open(array('action' => 'UserController#store')); }}
{{ Form::text('username', null, array('class' => 'input-small', 'placeholder' => 'Email')); }}
<p>{{ Form::password('password', array('class' => 'input-small', 'placeholder' => 'Password')); }}
{{ Form::hidden('category', 2) }}
{{ Form::label('name', 'Name:', array('class' => 'col-sm-3')) }}
{{ Form::text('name') }}
{{ Form::label('description', 'Company Description:', array('class' => 'col-sm-3')) }}
{{ Form::text('description') }}
{{ Form::label('industry', 'Industry', array('class' => 'col-sm-3')) }}
{{ Form::text('industry') }}
{{ Form::label('phone', 'Phone Number:', array('class' => 'col-sm-3')) }}
{{ Form::text('phone') }}
<p>{{ Form::submit('Sign in'); }}
{{ Form::close(); }}
#else
<p>just a test for New User Page
#endif
#stop
The create page so far just results in getting the #else condition back. ie: "just a test for New User Page"
Thanks in advance

i will avoid all your codes because you are making it way complicated than it is.
i will explain in step by step.
make two views. one for job seeker, one for employer.
depending upon the category, load the respective view. that's all you want.
let's come to code.
Routes.php
Route::get('create/{category}', array(
'as' => 'create',
'uses' => 'UserController#create'
));
UserController
public function create($category)
{
if($category==1)
return View::make('seeker');
elseif($category==2)
return View::make('employer');
else
App::abort(400);
}
that's it. no need to touch the layout. Avoid putting logics in layout as possible. in longer run, it will be a mess.

Related

How can select and load form?

I want to select option 1 and load a form with inputs
HTML:
<select id="orden" class="form-control" name="orden">
<option disabled selected>Selecciona una opción</option>
<option value="1">{{ results.1.op_ser_codigo }}{{ results.1.op_num_codigo }} / ({{ results.1.data_ini }} - {{ results.1.data_fim }})</option>
<option value="2">{{ results.2.op_ser_codigo }}{{ results.2.op_num_codigo }} / ({{ results.2.data_ini }} - {{ results.2.data_fim }})</option>
<option value="3">{{ results.3.op_ser_codigo }}{{ results.3.op_num_codigo }} / ({{ results.3.data_ini }} - {{ results.3.data_fim }})</option>
<option value="4">{{ results.4.op_ser_codigo }}{{ results.4.op_num_codigo }} / ({{ results.4.data_ini }} - {{ results.4.data_fim }})</option>
<option value="5">{{ results.5.op_ser_codigo }}{{ results.5.op_num_codigo }} / ({{ results.5.data_ini }} - {{ results.5.data_fim }})</option>
<option value="6">{{ results.6.op_ser_codigo }}{{ results.6.op_num_codigo }} / ({{ results.6.data_ini }} - {{ results.6.data_fim }})</option>
</select>
I want to fill this: (If on select option i select 1 on this inputs fill value 1)
<b><p class="black">OP: </b>{{ results.1.op_ser_codigo }}{{results.1.op_num_codigo}} </p>
<b><p class="black">Fecha Inicio: </b>{{ results.1.data_ini }} </p>
<b><p class="black">Fecha Final: </b> {{ results.1.data_fim }} </p>
You can handle it on client side (with jq, javascript) or on the server side. I definitely advice to handle it on the server side - as business logic should be there. Although in this case - as I understand - the trigger will come after the form is loaded and once the select options is selected.
I would go with an ajax solution.
place an onchange event to the select:
eg:
onchange="ChooseOption(this.value)"
add javascript to handle ajax request(I use jquery):
function ChooseOption(option_id){
$.ajax({
type: "POST",
url: "/applicatioin/option_selection/",
data: {
'option_id' : option_id,
'csrfmiddlewaretoken' :
$("input[name=csrfmiddlewaretoken]").val()
},
success: chooseoptionDetailSuccess,
dataType: 'html'
});
}
In the success you call chooseoptionDetailSuccess function. Which should pass the data to the relevant html field - with innerHtml.
Note: you may also use GET request type.
In you django view you have to render a html template which holds the html part (with the variables) which will be changed.
Sorry for the format. Seems like the code sample is not working.

I want to add a custom png image instead of glyphicon in admin menu section in opencart 2.3x and 3x?

how do i update this, in column_left controller?
if ($catalog) {
$data['menus'][] = array(
'id' => 'menu-catalog',
'icon' => 'fa-tags',
'name' => $this->language->get('text_catalog'),
'href' => '',
'children' => $catalog
);
}
you can't because it is hardcoded for evey menu,
and even you manage to get this done , some other extension you installed still need that update fix
in column left controller
'icon' => 'fa-tags', chaange it to 'icon' => 'glyphicon glyphicon-user'
nothing to change in view , it will work ,
You should customize the html in "admin/view/template/common/column_left.twig"
For example .. replace this code :
{% if menu.href %}<i class="fa {{ menu.icon }} fw"></i> {{ menu.name }}
by:
{% if menu.href %}{% if menu.img %}<img src="{{ menu.img }}"> {{ menu.name }}{% else %}<i class="fa {{ menu.icon }} fw"></i> {{ menu.name }}{% endif %}
and adding the image path in menu array item in column_left controller :
'img' => 'view/image/file.png'

How to set vue data to the value of a form?

I have a flask page that is for editing blog posts. It has the following vue:
<form method="POST" action="{{ url_for('edit',itemid=item.id) }}" id="text-input">
{{ form.csrf_token }}
<div style="margin-left:30px;margin-top:20px;">
Title: {{ form.title }}
</div>
<br/>
<div id="editor">
Content: {{ form.content( **{':value':'input','#input': 'update'}) }}
<div v-html="compiledMarkdown"></div>
</div>
<br/>
Category: {{ form.category|safe }}
<br/>
<input type="submit" value="Save">
</form>
<script>
new Vue({
el: '#editor',
data: {
input: "starting data"
},
computed: {
compiledMarkdown: function () {
return marked(this.input, { sanitize: true })
}
},
methods: {
update: _.debounce(function (e) {
this.input = e.target.value
}, 300)
}
});
</script>
What I would like to do is have a starting value for input based on something sent in by flask. Basically I would change input: "starting data" to input: {{ form.content.data }}. However, when I do this, it stops updating the input when I change the text in the box. I think I am kind of hardcoding the data to be whatever what in form.content.data as opposed to a string.
How can I pass this in so that it starts with the form.content.data value yet is still changeable?
The reason it didn't work was because {{ form.content.data }} appears in the template as raw text.
Thus it was trying to use something like: the brown fox jumped over the lazy dog
and this doesn't compile to a javascript object. Adding quotes around the {{ form.content.data }} like '{{ form.content.data }}' fixed it.

Sending mail using Laravel 4.2 and Mailgun

i'm little bit new to this.
I had read the documentation of Laravel 4 and some of the Mailgun, I had tested some mail and worked but just in route like this:
Route::get('send_test_email', function(){
Mail::send('emails.registro', array('key' => 'value'), function($message)
{
$message->subject('Bienvenido a la gran experiencia');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to('luis02lopez#hotmail.com');
});
});
I went to myapp/send_test_email in the browser and get an email.
But now I want to send an email at registration, I created the route:
Route::get('mail', ['uses' => 'MailController#send', 'as' => 'send']);
The controller:
<?php
class MailController extends \BaseController {
public function index()
{
return View::make('signup');
}
public function send() {
Mail::send('emails.registro', $data, function($message) use
           {
           $message->subject('Bienvenido a la gran experiencia');
           
           $message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
           
           $message->to($user->email, $user->firstname);
           });
}
And added a form to the signup form like this:
{{ Form::open(['route' => 'send', 'method' => 'get']) }}
<div class="form-group">
{{ Form::label('username', 'Usuario', ['class' => 'sr-only']) }}
{{ Form::text('username', null, ['placeholder' => 'Usuario', 'required', 'minlength' => 6, 'class' => 'form-control', ]) }}
#foreach($errors->get('username', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('password', 'Contraseña', ['class' => 'sr-only']) }}
{{ Form::password('password', ['placeholder' => 'Contraseña', 'required', 'minlength' => 8, 'class' => 'form-control']) }}
#foreach($errors->get('password', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('password_confirm', 'Confirmar Contraseña', ['class' => 'sr-only']) }}
{{ Form::password('password_confirmation', ['placeholder' => 'Confirmar Contraseña', 'required', 'minlength' => 8, 'class' => 'form-control']) }}
#foreach($errors->get('password_confirmation', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('email', 'Email', ['class' => 'sr-only']) }}
{{ Form::email('email', null, ['placeholder' => 'Email', 'required', 'class' => 'form-control']) }}
#foreach($errors->get('email', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('firstname', 'Nombres', ['class' => 'sr-only']) }}
{{ Form::text('firstname', null, ['placeholder' => 'Nombres', 'required', 'class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('lastname', 'Apellidos', ['class' => 'sr-only']) }}
{{ Form::text('lastname', null, ['placeholder' => 'Apellidos', 'required', 'class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::submit('Registrar', ['class' => 'btn btn-lg btn-block btn-kinbu'])}}
</div>
{{ Form::close() }}
And I got a Parse error: syntax error, unexpected 'Mail' (T_STRING) in the controller, why?
Here I have errors:
public function send() {
Mail::send('emails.registro', $data, function($message) use
{
$message->subject('Bienvenido a la gran experiencia');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to($user->email, $user->firstname);
});
}
I'm using the $user var, but I'm not passing it with the closure "user" so I have to do:
public function send() {
Mail::send('emails.registro', array('key' => 'value'), function($message) use ($user)
{
$message->subject('Bienvenido a la gran experiencia');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to($user->email, $user->firstname);
});
}

Laravel Select Menu / Dropdown

I am using the following code:
<select onchange="javascript:location.href = this.value;">
<option value="" selected>-- Show Genre --</option>
#foreach ($genres as $genre)
<option value="{{ URL::route('tracks.order', array('order' => 'name', 'by' => 'asc', 'genre' => $genre->name )) }}">{{ $genre->name }}</option>
#endforeach
</select>
The $genres is populated using the following code in my controller:
$genres = Genres::lists('name', 'id');
I was wondering if I could use a code like below instead of the foreach? I think I should be able to, but I have no clue on how to change the code to work with my code above.
{{ Form::select('genre', array('default' => '-- Select Genre --') + $genres, '') }}
You may try something like this:
$genres = ['default' => '-- Select Genre --'] + Genres::lists('name', 'id');
In the view:
{{ Form::select('genre', $genres, Form::old('genre')) }}