i'm using an AdminLTE package with Laravel to give me the AdminLTE theme for my app.
I cannot get the modal to launch at all. If I copy the contents of my form.blade.php into my index.blade.php it works. Although the way i have coded my controller & views i need them to be independent files.
Index.blade.php <- view serving the datatable
form.blade.php <-- view serving the modal from click edit on index.blade.php
CostCenterController.php <-- Controller responsible for both views.
CostCenterController.php
So in my controller I have a function that returns the results with server side processing into my datatable, this is just the part showing how each item in the table is generated, specifically with the btn-group for the edit function.:
$data = array();
if (!empty($costcenters)){
foreach ($costcenters as $costcenter){
$editURL = "delete/".$costcenter->id;
$temp['name'] = $costcenter->name;
$temp['code'] = $costcenter->code;
$action = '';
$action .= '
<div class="btn-group">
<i class="fa fa-edit"></i>
<i class="fa fa-trash"></i>
</div>
';
$temp['action'] = $action;
array_push($data, $temp);
}//end for each
}// end if empty
$recordsTotal = count($recordsTotal);
echo json_encode(array('recordsTotal' => $recordsTotal, 'data' => $data, 'recordsFiltered' => $recordsTotal));
In my index.blade.php i have nothing of importance or relevance really.
form.blade.php
I created a form.blade.php so when I hit edit, a route calls this view with the data needed from the edit function in the associated controller. This view works as plain html if opened in a new tab.
<div class="modal fade" id="modal" role="dialog">
<div class="modal-dialog" >
#if ($mode == 'edit')
{!! Form::model($costcenter,array('route'=>array('costcenter.update',$costcenter->id),'id'=>'costcenter-form')) !!}
#else
{!! Form::open(array('url'=>'costcenter/store','method'=>'post','data-toggle'=>'validator','id'=>'costcenter-form')) !!}
#endif
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
#if ($mode == 'edit')
Edit {{$costcenter->name}}'s Cost Center
#else
Create Cost Center
#endif
</h5>
<button aria-label="Close" class="close" data-dismiss="modal" type="button"><span aria-hidden="true"> ×</span></button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
{!! Form::label('name','Cost Center Name:',['class'=>'control-label']) !!}
{!! Form::text('name',null,['class'=>'form-control','placeholder'=>'Enter Cost Center Name','data-error'=>"Please enter the name of the cost center",'required'=>true]) !!}
</div>
<div class="form-group">
{!! Form::label('code','CostCenter Code:',['class'=>'control-label']) !!}
{!! Form::text('code',null,['class'=>'form-control','placeholder'=>'Cost Center code as it appears in SYSPRO.','data-error'=>"Invalid Cost Center Code.",'required'=>true]) !!}
</div>
</form>
</div>
<div class="modal-footer">
{!! Form::submit('Save',['class'=>'btn btn-primary'])!!}
</div>
</div>
</div>
</div>
Any help would be appreciated.
Related
I have succesfully created an application within Laravel which allows users to edit posts for a item. The current method is by redirecting user to different page where they are able to make changes. However to increase the user expirence I was planning to add 'modal' within the page. Meaning that editing posts will happen within the same page. This method for me partly works. In a aspect that the last or the latest post is only editable post. If I click on any of the posts it makes me only make changes to the latest post. Any help, suggestions or examples are trully appreciated.
Below I have attached my show.blade.php which shows the item infromation and posts.
<ul class="list-group">
#foreach ($car->reviews as $review)
<li class="list-group-item">
<strong>
Created by: {{ $review->user->name}} {{ $review->created_at->diffForHumans() }}:
<br>
Updated by: {{ $review->user->name}} {{ $review->updated_at->diffForHumans() }}:
</strong>
<a href="/reviews/{{ $review->id }}/edit" data-toggle="modal" data-target="#myModal1" >{{ $review->reviewbody }}</a>
<a style="float:right;" href="/reviews/{{$review->id}}/delete">Delete</a>
#endforeach
The Modal
<div class="container">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal1">TEST</button>
<!-- Modal -->
<div class="modal fade" id="myModal1" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<div class="review-edit">
<div class="review-edit-block">
{{ $review->reviewbody }}
<form action="/reviews/{{$review->id}}" method="POST">
{{ csrf_field() }}
{{ method_field('patch') }}
<div class="form-group">
<textarea style="position:relative;left:10%;width:375px;"name="reviewbody" class="form-control">{{ $review->reviewbody }}</textarea>
</div>
<div>
<button type="submit" class="btn btn-primary">Update Review</button>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
If the modal is included after the foreach loop, the variable $review will still be set to the value of the last item in the array.
An option is to use Javascript to handle the clicked link, set the specific data into the modal fields and then make the modal visible.
Example
I have a very strange issue in one of my projects. I have a redirect route in one of my controllers that redirects and opens a route but does not work.
I know this sounds vague and I will do my best to explain. I have a view with a some href's on it that sends a get request to controller this controller calls a handler and the handler inserts some records and then the controller redirects back to the original route.
At the moment when i click on it the get request fires the records get inserted correctly and i get back on the originial page but here is the problem the original page is still in the old state and not updated. I have to refresh the page manually to see the changes take effect. I can click the same href a hunderd times without anything updating in the view.
To make it even worse the same exact codes works fine on the local development environment and on the staging evironment this just happens on the production environment.
My view:
#extends('layouts.master')
#section('title', 'Trajecten')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-12">
#if (Session::has('status'))
<div class="alert alert-success">
<ul>
<li>{{Session::get('status')}}</li>
</ul>
</div>
#endif
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
</div>
</div>
<div class="row">
<div class="col-md-12">
<a href="#" data-toggle="modal" data-target="#contactModal">
<button type="submit" class="btn btn-primary btn-orange pull-right">
Meld nieuwe inkoop behoefte
</button>
</a>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Product/dienst</th>
<th>Geïnteresseerd</th>
<th>Deelnemen t/m</th>
<th>Informatie</th>
<th>Deelnemen</th>
</tr>
</thead>
#foreach($trajects as $traject)
<tr>
<td>{{$traject->name}}</td>
<td>{{$traject->deelnemers->count() + $traject->participants}}</td>
<td>{{date('d-m-Y', strtotime($traject->tot))}}</td>
<td>Klik hier voor meer informatie</td>
<td>#if(in_array($traject->id, $usertrajects)) U bent geregistreerd als geïnteresseerde #else Klik hier voor deelname #endif</td>
</tr>
#endforeach
</table>
</div>
</div>
#foreach($trajects as $traject)
<div class="modal fade" id="trajectmodal{{$traject->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Meer informatie voor {{$traject->name}}</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
{!!$traject->description!!}
</div>
</div>
</div>
<div class="modal-footer text-center">
#if($traject->conditie != "")<a target="__blank" href="{{$traject->conditie}}" onclick="log(11,2,{{$traject->id}})"><button type="button" class="btn btn-default pull-left btn-orange">Conditie</button></a>#endif
#if($traject->product != "")<a target="__blank" href="{{$traject->product}}" onclick="log(12,2,{{$traject->id}})"><button type="button" class="btn btn-default btn-orange">Product</button></a>#endif
#if($traject->leverancier != "")<a target="__blank" href="{{$traject->leverancier}}" onclick="log(13,2,{{$traject->id}})"><button type="button" class="btn btn-primary btn-orange">Leverancier</button></a>#endif
</div>
</div>
</div>
</div>
#endforeach
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="contactModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="gridSystemModalLabel">Meldpunt inkoop behoefte</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form" id="meldinkoopbehoefte" method="post">
{!! csrf_field() !!}
<div class="form-group">
<label for="subject" class="col-sm-3 text-left control-label">Inkoop behoefte</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="subject" name="subject" placeholder="Onderwerp" value="">
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-3 text-left control-label">Bericht</label>
<div class="col-sm-9">
<textarea class="form-control" rows="4" placeholder="Bericht" name="message"></textarea>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" onclick="javascript:$('#meldinkoopbehoefte').submit()" class="btn btn-primary btn-orange">Verstuur</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
#endsection
My method in the controller
Changing the route to another page i see the changes take effect like the session flash. So i am suspecting my view at this point.
public function participate($id){
if(TrajectHandler::participate($id)){
Session::flash('status', 'Uw interesse of voorstel is ontvangen');
}
//Changing the route to another page i see the changes take effect.
//So i am suspecting my view at this point.
return redirect()->route('traject.index');
}
The index method in the controller
public function index(){
$trajects = TrajectHandler::getTrajects();
$userTrajects = TrajectHandler::getUserTrajects();
foreach ($trajects as $traject) {
if (!is_null(ViewedUserTraject::where('user_id', Auth::id())
->where('traject_id', $traject->id)->first()))
continue;
$viewedTraject = new ViewedUserTraject();
$viewedTraject->user_id = Auth::id();
$viewedTraject->traject_id = $traject->id;
$viewedTraject->save();
}
return view('traject.index', [
'trajects' => $trajects,
'usertrajects' => $userTrajects
]);
}
Another method in the controlller
I decided to add this method in the question as it is basically the exact same thing but does work.
public function suggestTraject(ContactRequest $request){
Mailer::inkoopBehoefteMail(Auth::user(), $request->subject, $request->message);
Session::flash('status', 'Inkoop behoeften verstuurd.');
return redirect()->route('traject.index');
}
The participate method in the TrajectHandler
public static function participate($id){
$count = TrajectUser::where('user_id' , Auth::id())->where('traject_id', $id)->get();
if (count($count) == 0) {
$traject = new TrajectUser;
$traject->traject_id = $id;
$traject->user_id = Auth::id();
if($traject->save()){
Logger::log(Auth::id(),5,2,$id);
Mailer::newTrajectUser(Auth::user(), Traject::find($id));
return true;
}
return false;
}
return true;
}
My routes
Route::group(['prefix' => 'traject'], function(){
Route::get('', ['as' => 'traject.index' , 'uses' => 'User\TrajectController#index']);
Route::post('', ['as' => 'traject.index' , 'uses' => 'User\TrajectController#suggestTraject']);
Route::get('participate/{id}', ['as' => 'traject.participate' , 'uses' => 'User\TrajectController#participate']);
});
Seems like it had something to do with caching.
Adding the following headers in my routes file fixed the issued for me.
header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
Does the php version on the production environment meets the minimum required php version for Laravel? For Laravel 5.2 you need php 5.5.9. See the Laravel Docs
I am doing project in laravel. I have multiple records in databse which I have displayed in laravel's blade file using foreach loop. Each record have pending button. Whenever user clicks on pending button it opens a html modal. I want that record id inside the modal but it always take first record id. My blade file looks like,
#foreach($providerData as $newprovider)
<h4>Name:{{$newprovider->name}}</h4>
<button class="btn btn-default" data-toggle="modal" data-target="#Pendingnote">Pending</button>
{!! Form::model( $newprovider->id ,['method' => 'PATCH','action'=>['superadminController#pendingProvider', $newprovider->id]]) !!}
<div class="modal fade" id="Pendingnote" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Note {!! $newprovider->id !!}</h4>
</div>
<div class="modal-body">
<input type="text" class="form-control" name="note" value="{{ old('note') }}">
</div>
<div class="modal-footer">
{!! Form::submit('Add', ['class' => 'btn btn-default']) !!}
</div>
</div>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</div>
{!! Form::close() !!}
#endforeach
Whichever record is clicked, it always returns $newprovider->id as first record's id. I don't know where I am getting wrong. Please help and thanks in advance.
Do these things in order to get the modals work.
Edit the button to:
<button class="btn btn-default" data-toggle="modal" data-target="#Pendingnote{{$newprovider->id}}">Pending</button>
And the modal container to:
<div class="modal fade" id="Pendingnote{{$newprovider->id}}" role="dialog">
All modal-triggering buttons have data-target="#Pendingnote", which means they all trigger the first modal with that id they can find.
You could try for instance removing the data-target attribute and trigger the modal with a bit of jQuery, like:
$('button[data-toggle]').on('click', function () {
$(this).next('form').find('.modal').modal('show');
});
I would suggest anyway to have the forminside the modal instead. So the jQuery would be:
$('button[data-toggle]').on('click', function () {
$(this).next('.modal').modal('show');
});
Lastly, take a look at this: http://getbootstrap.com/javascript/#modals-related-target
I'm trying to update an existing row in my table using a form in a bootstrap modal. But nothing changes when I attempt it. I have an html table with a list of cars and in each row a button "Change Status" that opens the bootstrap modal with the id="myModal_{{ $car->id }}" and with the form inside it to edit the status of a car in repair.
Here's my modal:
<!-- Modal -->
<div class="modal fade" id="myModal_{{ $car->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Breyta stöðu bíls</h4>
</div>
<div class="modal-body">
<div class="form-group">
<h3>Breyta stöðu fyrir {{ $car->LicencePlate }}</h3>
</div>
{!! Form::open(['url' => 'create']) !!}
<div class="form-group">
{!! Form::label('Status', 'Status: ') !!}
{!! Form::select('Status', [
null => ' -- Veldu Stöðu bíls -- ',
'Í Biðröð' => 'Í Biðröð',
'Í Viðgerð' => 'Í Viðgerð',
'Tilbúinn' => 'Tilbúinn'
], null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{!! Form::submit('Skrá stöðu', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
Update method in CarController:
public function CarEdit($id, Requests\CreateCarsRequest $request)
{
$edit = Car::update($request->all());
return redirect::back();
}
My Route to that method:
Route::post('/dashboard', 'CarController#CarEdit');
You should do this:
['action' => 'CarController#CarEdit']
Also, you're using mass assignment, so you must fill $fillable array in your Car model to make it work:
https://laravel.com/docs/5.1/eloquent#mass-assignment
I was able to fix this with the help of my colleagues. What I did was I created a new requet called UpdateCarRequest where the LicencePlate field was not unique. And edited my method like so:
public function CarEdit(Requests\UpdateCarRequest $request)
{
$edit = Car::where('LicencePlate', '=', $request->LicencePlate)->first();
$edit->update($request->all());
return redirect('/dashboard');
}
I also added a hidden field in the form with the value $car->LicencePlate.
I'm having a register form and login form on my home page
the login form is activated when you press the login link (via bootstrap)
and the register form is visible all the time
now when one off those fails, I wanna send the error's to the page
but I can only access the var's of these:
return Redirect::to('/')->withErrors($validator)
->withInput(Input::except('password'));
but when I add ->with('method', 'login') I can't check in my home page the var $method
it's empty and never get's any values
can someone tell me what I might be doing wrong?
and also how I can activate the login form with variables that I send with the ->with()
the login form is made up like this:
<div class="modal fade bs-example-modal-sm pvvoModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Login to your account</h4>
</div>
{{ Form::open(array('url' => 'admin/login', 'class'=>'form', 'role' => 'form')) }}
<div class="modal-body">
#if ( $errors->first('username') != null || $errors->first('password') != null)
<div class="alert alert-danger">
<p>Some errors occured</p>
{{ $errors->first('username') }}
{{ $errors->first('password') }}
</div>
#endif
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="fa fa-user"></span></span>
{{ Form::text('username', $value = null, array('placeholder' => 'Username', 'class'=> 'form-control', 'required' => 'required', 'autofocus' => 'autofocus' )) }}
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="fa fa-asterisk"></span></span>
{{ Form::password('password', array('placeholder' => 'Password', 'class' => 'form-control', 'id'=>'password', 'required' => 'required')) }}
</div>
</div>
<div class="text-center">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ Form::submit('Login', array('class' => ' btn btn-primary')) }}
</div>
</div>
{{ Form::close() }}
</div><!-- /.modal-content -->
</div>
</div>
</div>
The with() method flashes data to the session, you have to retrieve your data using Session::get()method.
Source : Laravel doc
Fixed it by doing it via AJAX :)
was easier for keeping the login form open