How to pass values to vue data from laravel blade? - php

I am using Vue.js with Axios to post my data. But Axios returns NULL from my Laravel Controller. Input text is empty when using v-model (update form - blade laravel).
Pretty new to this awesome framework. I need to make an AJAX call for a text input in an update form (blade laravel), however in the form the input is blank and I’m having trouble to figure out if I’m missing something.
Question:
How do I send the input value from the blade template when the form is loaded to the Vue data instance
Blade:
{!! Form::open(['url' => '','class'=>'form-horizontal', 'id'=>'smv-cost-form','enctype'=>'multipart/form-data']) !!}
{!! Form::hidden('trans_id_d','36', ['class' => 'custom-input-bom','readonly'=>'readonly']) !!}
<tr id="smvCostAdd">
<td colspan="2">
{!! Form::text('knittingCost','',['class'=>'input-custom form-control','id'=>'knittingCost','v-model'=>'smvCostModel.knittingCost']) !!}
<p class="error" v-if="knittingCost_error">#{{knittingCost_error}}</p>
</td>
<td colspan="2">
{!! Form::text('linkingCost','',['class'=>'input-custom form-control','id'=>'linkingCost','v-model'=>'smvCostModel.linkingCost']) !!}
<p class="error" v-if="linkingCost_error">#{{linkingCost_error}}</p>
</td>
<td colspan="2">
{!! Form::text('tremingCost','',['class'=>'input-custom form-control','id'=>'tremingCost','v-model'=>'smvCostModel.tremingCost']) !!}
<p class="error" v-if="tremingCost_error">#{{tremingCost_error}}</p>
</td>
<td colspan="2">
{!! Form::text('mendingCost','',['class'=>'input-custom form-control','id'=>'mendingCost','v-model'=>'smvCostModel.mendingCost']) !!}
<p class="error" v-if="mendingCost_error">#{{mendingCost_error}}</p>
</td>
<td colspan="2">
{!! Form::text('washCost','',['class'=>'input-custom form-control','id'=>'washCost','v-model'=>'smvCostModel.washCost']) !!}
<p class="error" v-if="washCost_error">#{{washCost_error}}</p>
</td>
<td colspan="2">
{!! Form::text('pcqCost','',['class'=>'input-custom form-control','id'=>'pcqCost','v-model'=>'smvCostModel.pcqCost']) !!}
<p class="error" v-if="pcqCost_error">#{{pcqCost_error}}</p>
</td>
<td>
{!! Form::text('ironCost','',['class'=>'input-custom form-control','id'=>'ironCost','v-model'=>'smvCostModel.ironCost']) !!}
<p class="error" v-if="ironCost_error">#{{ironCost_error}}</p>
</td>
<td>
{!! Form::text('sewingCost','',['class'=>'input-custom form-control','id'=>'sewingCost','v-model'=>'smvCostModel.sewingCost']) !!}
<p class="error" v-if="sewingCost_error">#{{sewingCost_error}}</p>
</td>
<td>
{!! Form::text('packingCost','',['class'=>'input-custom form-control','id'=>'packingCost','v-model'=>'smvCostModel.packingCost']) !!}
<p class="error" v-if="packingCost_error">#{{packingCost_error}</p>
</td>
<td></td>
<td>{!! Form::button('Save', ['class' => 'btn btn-primary', 'v-on:click.prevent'=>'saveSMVcost();'] ) !!}</td>
</tr>
{!! Form::close() !!}
JS:
saveSMVcost: function () {
/*var request = new XMLHttpRequest();*/
var form = document.querySelectorAll("#smv-cost-form");
var formData = new FormData(form);
var base_url = window.location.origin;
var page_url = base_url + '/bca/smv-cost-action';
$('#ajax-call-effect').show();
console.log(formData.knittingCost);
alert(formData.knittingCost);
axios.post(page_url, formData).then(
function (response) {
$('#ajax-call-effect').hide();
if (response.data.errors) {
response.data.errors.knittingCost ? app.knittingCost_error = response.data.errors.knittingCost[0] : app.knittingCost_error = '';
response.data.errors.linkingCost ? app.linkingCost_error = response.data.errors.linkingCost[0] : app.linkingCost_error = '';
response.data.errors.tremingCost ? app.tremingCost_error = response.data.errors.tremingCost[0] : app.tremingCost_error = '';
response.data.errors.mendingCost ? app.mendingCost_error = response.data.errors.mendingCost[0] : app.mendingCost_error = '';
response.data.errors.washCost ? app.washCost_error = response.data.errors.washCost[0] : app.washCost_error = '';
response.data.errors.pcqCost ? app.pcqCost_error = response.data.errors.pcqCost[0] : app.pcqCost_error = '';
response.data.errors.ironCost ? app.ironCost_error = response.data.errors.ironCost[0] : app.ironCost_error = '';
response.data.errors.sewingCost ? app.sewingCost_error = response.data.errors.sewingCost[0] : app.sewingCost_error = '';
response.data.errors.packingCost ? app.packingCost_error = response.data.errors.packingCost[0] : app.packingCost_error = '';
}
else {
/* $('#knittingCost').val('');
$('#linkingCost').val('');
$('#tremingCost').val('');
$('#mendingCost').val('');
$('#washCost').val('');
$('#pcqCost').val('');
$('#ironCost').val('');
$('#sewingCost').val('');
$('#packingCost').val('');*/
app.knittingCost_error = '';
app.linkingCost_error = '';
app.tremingCost_error = '';
app.mendingCost_error = '';
app.washCost_error = '';
app.pcqCost_error = '';
app.ironCost_error = '';
app.sewingCost_error = '';
app.packingCost_error = '';
app.showNotification('top', 'center', response.data.status, response.data.message);
}
})
}

There are a few ways, but one would be to json_encode the object or array, as shown below. I ususally set a global object and then grab that in my Javascript, but you could technically set this value directly to a JS variable. Use #php and #endphp if you want more blade-like syntax.
<!-- Global App Object -->
<script>
window.App = <?php echo json_encode(
'isAdmin' => user()->isAdmin(),
'credentials' => user()->softphone()->credentials(),
'forwardToCellphone' => user()->forward_to_cellphone,
'status' => (new App\Http\Controllers\Users\UserStatusController)->details(),
); ?>;
</script>

Related

How to insert and delete record in database which is using dynamic fields Laravel?

I am using Laravel 5. In this application, the staff name can be added and deleted dynamically. For creating new records, all functions run smoothly. However, I have some difficulties in updating the records. In 'edit' page, the staff names created are displayed and can be changed. These names can be updated. But, I put add button and delete button to enable user to add new staff name or delete existing staff name.
My function just can update existing record in database. But the new added staff name not inserted in database. This is my function to update in controller.
public function update(Request $request, $id)
{
$demo = Demo::findOrFail($id);
$demo->tajuk_demo = $request->tajuk_demo;
$demo->syarikat_id = $request->nama_syarikat;
$demo->peralatan_sistem = $request->peralatan_sistem;
$demo->tarikhmasa = $request->tarikhmasa;
$demo->tarikhmasa_tamat = $request->tarikhmasa_tamat;
$demo->tempat_demo = $request->tempat_demo;
$demo->ulasan_demo = $request->ulasan_demo;
$demo->komen_demo = $request->komen_demo;
$demo->update();
$pegawai = $request->all();
// $rekod_id = $pegawai['rekod_id'];
$itemRegistrationID = $pegawai['nama'];
$OperasiID = $pegawai['pangkat'];
$SectionID = $pegawai['bahagian'];
$pegawai_semasa = Pegawai::where('rekod_id', '=', Input::get('rekod_id'))->exists();
$peg_hadir = Pegawai::where('demo_id', '=', $id)
->get();
// Update the existing record
foreach($peg_hadir as $peg){
$key = array_search($peg->rekod_id, $pegawai['rekod_id']);
$peg->itemRegistrationID = $itemRegistrationID[$key];
$peg->OperasiID = $OperasiID[$key];
$peg->SectionID = $SectionID[$key];
$peg->save();
}
if (is_null($pegawai_semasa))
{
// Insert new record into database
$count = count(Input::get('nama'));
// get data
$itemRegistrationID = Input::get('nama');
$OperasiID = Input::get('pangkat');
$SectionID = Input::get('bahagian');
//loop through and save data
for($i = 0; $i < $count; ++$i) {
$pegawai = new Pegawai;
$pegawai->demo_id = $id;
$pegawai->itemRegistrationID = $itemRegistrationID[$i];
$pegawai->OperasiID = $OperasiID[$i];
$pegawai->SectionID = $SectionID[$i];
$pegawai->save();
}
}
else
{
return redirect('demo');
}
}
This is the code in view blade for edit page:
<div class="form-group">
<div class="row">
<input type="button" class="add-row" value="Add">
<button type="button" class="delete-row">Delete</button>
</div>
</div>
<!--mula table -->
<div class="form-group">
<div class="row">
<div class="col-lg-10">
<table class="table table-striped table-bordered" id="pegawaihadir_table" >
<thead>
<tr>
<td class="text-center col-lg-1"><strong>Pilih</strong></td>
<td class="text-center col-lg-1"><strong>Pangkat</strong></td>
<td class="text-center col-lg-3"><strong>Nama</strong></td>
<td class="text-center col-lg-2"><strong>No Badan</strong></td>
<td class="text-center col-lg-2"><strong>Seksyen</strong></td>
<td class="text-center col-lg-2"><strong>No Tel</strong></td>
<td class="text-center col-lg-2"><strong>Ext</strong></td>
</tr>
</thead>
<tbody>
#foreach($PegawaiHadir as $value)
<tr>
<td><input type="checkbox" name="rekod" style="width:20px">
{!! Form::hidden('rekod_id[]', $value['rekod_id'], ['class' => 'form-control']) !!}
</td>
<td class="text-center">{{ Form::text('pangkat[]', $value['OperasiID'], ['class' => 'form-control pangkat', 'readonly' => 'true']) }}</td>
<td>
{{ Form::select('nama[]', $pegawai, $value['itemRegistrationID'], ['class' => 'form-control nama', 'required' => '']) }}
</td>
<td class="text-center">{{ Form::text('no[]', $value['Nobadan'], ['class' => 'form-control no', 'readonly' => 'true']) }}</td>
<td class="text-center">{{ Form::text('bahagian[]', $value['SectionID'], ['class' => 'form-control bahagian', 'readonly' => 'true']) }}</td>
<td class="text-center">{{ Form::text('telefon[]', $value['notelttp'], ['class' => 'form-control telefon', 'readonly' => 'true']) }}</td>
<td class="text-center">{{ Form::text('ext[]', $value['ext'], ['class' => 'form-control ext', 'readonly' => 'true']) }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
For dynamic fields, I am using js code to add and delete the record displayed in the page.
<script>
count=1;
$(document).ready(function(){
$(".add-row").click(function(){
var markup = '<tr><td><input type="checkbox" name="rekod" style="width:20px"></td>';
markup += '<td><input type="text" class="form-control pangkat" name="pangkat[]" style="width:100px" readonly></td>';
markup += '<td><select class="form-control select2 nama" name="nama[]" style="width:300px"><option value="">Pilih</option><?php foreach($pegawai as $key => $value):echo '<option value="'.$key.'">'.addslashes($value).'</option>'; endforeach; ?></select></td>';
markup += '<td><input type="text" class="form-control no" name="no[]" style="width:100px" readonly></td>';
markup += '<td><input type="text" class="form-control bahagian" name="bahagian[]" style="width:100px" readonly></td>';
markup += '<td><input type="text" class="form-control telefon" name="telefon[]" style="width:100px" readonly></td>';
markup += '<td><input type="text" class="form-control ext" name="ext[]" style="width:100px" readonly></td></tr>';
$("table tbody").append(markup);
count++;
});
$(document).on('change', 'select.form-control.nama', function() {
var PegID = jQuery(this).val();
var row = $(this);
// alert(PegID);
if(PegID)
{
jQuery.ajax({
context: this,
url : 'get_pegawai/'+PegID,
type : "GET",
dataType : "json",
success:function(data)
{
console.log(data);
$(this).closest('tr').find('td .form-control.pangkat').val(data.operasiname);
$(this).closest('tr').find('td .form-control.no').val(data.Nobadan);
$(this).closest('tr').find('td .form-control.bahagian').val(data.sectionname);
$(this).closest('tr').find('td .form-control.telefon').val(data.notelttp);
$(this).closest('tr').find('td .form-control.ext').val(data.ext);
}
});
}
else
{
$(this).closest('tr').find('td .form-control.pangkat').empty();
$(this).closest('tr').find('td .form-control.no').empty();
$(this).closest('tr').find('td .form-control.bahagian').empty();
$(this).closest('tr').find('td .form-control.telefon').empty();
$(this).closest('tr').find('td .form-control.ext').empty();
}
});
// Find and remove selected table rows
$(".delete-row").click(function(){
$("table tbody").find('input[name="rekod"]').each(function(){
if($(this).is(":checked")){
$(this).parents("tr").remove();
}
});
});
});
</script>
I also doesn't know how to identify the selected staff name to be deleted from existing record in database. I am providing a complete code to ease anyone who want to help to understand better. Thank you.
Make this ajax call into an IIFE
$(function(){
$(document).on('change', 'select.form-control.nama', function() {
var PegID = jQuery(this).val();
var row = $(this);
// alert(PegID);
if(PegID)
{
jQuery.ajax({
context: this,
url : 'get_pegawai/'+PegID,
type : "GET",
dataType : "json",
success:function(data)
{
console.log(data);
$(this).closest('tr').find('td .form-control.pangkat').val(data.operasiname);
$(this).closest('tr').find('td .form-control.no').val(data.Nobadan);
$(this).closest('tr').find('td .form-control.bahagian').val(data.sectionname);
$(this).closest('tr').find('td .form-control.telefon').val(data.notelttp);
$(this).closest('tr').find('td .form-control.ext').val(data.ext);
}
});
}
else
{
$(this).closest('tr').find('td .form-control.pangkat').empty();
$(this).closest('tr').find('td .form-control.no').empty();
$(this).closest('tr').find('td .form-control.bahagian').empty();
$(this).closest('tr').find('td .form-control.telefon').empty();
$(this).closest('tr').find('td .form-control.ext').empty();
}
});
});
And also change update() method to save() method in your controller.

Laravel Blade - Append view to table tbody

I'm trying to append rows to a table but it don't pass <tr> and <td>, it's wired. Pass all without this two tags.
My jquery code is that:
$.get('/remove-day-travel/'+id, function(data)
{
$('#travelTable tbody').html('');
$('#travelTable tbody').append(data);
addDayTravel();
removeDayTravel();
});
My controller:
public function removeDayTravel($id)
{
$intervention = DB::table('interventionDays')->select('interventionId')->where('id', $id)->first();
//DB::table('interventionDays')->where('id', $id)->delete();
$travelHours = DB::table('interventionDays')
->where('interventionId', $intervention->interventionId)
->orderBy('day', 'ASC')
->get();
return view('current-dayTravel', compact('travelHours'));
}
And my view is that:
#if(count($travelHours) > 0)
<?php $count = 1; ?>
#foreach ($travelHours as $key => $value)
<input type="hidden" name="day-travel-id[{{$count}}]" value="{{$value->id}}">
<input type="hidden" name="day-travel-remove[{{$count}}]" value="0">
<tr>
<td><label>Dia {{$count}}:</label></td>
<td><label>Ida</label></td>
<td class="#if ($errors->has('hour-day-1[' . $count . ']')) has-error #endif">
{!! Form::text('hour-day-1[' . $count . ']', $value->morningStart , ['class' => 'form-control travelGoStartHour', 'placeholder'=> '']) !!}
</td>
<td class="#if ($errors->has('hour-day-2[{{$count}}]')) has-error #endif">
{!! Form::text('hour-day-2[' . $count. ']', $value->morningEnd, ['class' => 'form-control travelGoEndHour', 'placeholder'=> '']) !!}
</td>
<td>
<label>Volta</label>
</td>
<td class="#if ($errors->has('hour-day-3[' . $count . ']')) has-error #endif">
{!! Form::text('hour-day-3[' . $count . ']', $value->afternoonStart, ['class' => 'form-control travelBackStartHour', 'placeholder'=> '']) !!}
</td>
<td class="#if ($errors->has('hour-day-4[' . $count . ']')) has-error #endif">
{!! Form::text('hour-day-4[' . $count . ']', $value->afternoonEnd, ['class' => 'form-control travelBackEndHour', 'placeholder'=> '']) !!}
</td>
<td>
{!! Form::checkbox('dinner[' . $count . ']', 0,$value->dinner) !!}
</td>
<td>
{!! Form::checkbox('stay[' . $count . ']', 0,$value->stay) !!}
</td>
<td>
#if($key == count($travelHours) -1)
<i class="icon-plus-circled add-new-day-travel" title="Adicionar Novo dia" data-id="1"></i>
#endif
</td>
<td>
#if($key == count($travelHours) -1)
<i class="icon-cancel remove-day-travel" title="Remover dia" data-id="{{$count}}" data-record="{{$value->id}}"></i>
#endif
</td>
</tr>
<?php $count += 1; ?>
#endforeach
#endif
But returns me this:
I don't understand why? What I'm doing wrong?
Thank you
$('#travelTable tbody').html(data);
Use the above in your JS instead of what you currently have
When you render a tr or th or even td tag outside a tbody or thead or tfooter html ignores them and replace them by a empty space because those tags can only be placed in between opening and closing table tags.
Browsers ignore the <tbody>, <tr>, and <td> tags and the corresponding end tags. This has not been specified in HTML specifications, since they do not define the parsing of syntactically erroneous documents. In the HTML5 draft, however, there is a description that defines the browser behavior in a manner that corresponds to the what browsers actually do: Tree construction.
This means that you cannot write an HTML document that contains, say, a element outside a table element. The HTML parser in a browser simply does not construct such document trees. (You can, however, construct such a document dynamically with client-side scription.)
See previous answer here:
How do browsers analyze <tr> <td> without <table>?

getting method not allowed exception when send ajax with post method

i develop web application with laravel 5.2 , i try to send an array with ajax to my controller , the request sent but after that i saw the error :405 method not allowed , i searched many times but this problem didn't solve :
my ajax code is :
// send array of stream checkbox to controller
$('#json-btn').click(function () {
var input = $("form input:checkbox");
var stream = [];
$.each($(input), function(){
stream.push($(this).val());
});
var jstream = JSON.stringify(stream);
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
$.ajax({
url: '/ajaxGet/',
type: 'POST',
data: {_token: CSRF_TOKEN , jstream:jstream},
dataType: 'JSON',
success: function (data) {
alert(data);
}
});
});
my route is :
Route::post('ajaxGet', 'ajaxController#getRequest');
my controller is :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class ajaxController extends Controller
{
public function getRequest(Request $request)
{
echo $request['jstream'];
}
}
and finally this is my form :
{!! Form::open(array('id' => 'trailer-form')) !!}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<table dir="rtl">
<thead>
<tr>
<th>quality</th>
<th>link</th>
<th>steram</th>
</tr>
</thead>
<tbody>
<tr>
<td>
{!! Form::select('quality[]', array('noQuality'=>'select...','64p'=>'64p','144p'=>'144p','240p'=>'240p','360p'=>'360p','480p'=>'480p','720p'=>'720p', '1080p'=>'1080p'), null , ['class'=> 'form-control lns' , 'id' => 'quality-input']) !!}
</td>
<td>
{!! Form::text('downLoadLink[]',null,['class' => 'form-control ln' , 'id' => 'down-input']) !!}
</td>
<td>
{!! Form::checkbox('stream[]','false',null,['class' => 'form-control' , 'id' => 'streamCheck' , 'onchange' => 'createAlerts(this)']) !!}
</td>
<td>
<button class="btn btn-success btn-add" type="button">
<i class="glyphicon glyphicon-plus gs"></i>
</button>
</td>
</tr>
</tbody>
</table>
{!! Form::submit('json create',['class' => 'btn btn-success' , 'id' => 'json-btn']) !!}
{!! Form::close() !!}
please help me to solve this problem thank you so very much :)

How to submit files in Laravel

My form is as follow
{{ Form::open(array( 'enctype' => 'multipart/form-data'))}}
<div class="vendor-box-wrap">
<div class="page3-suggested-cat-wrap" style="float: left;width: 100%;border-bottom: 1px dotted;padding-bottom: 10px;margin-left: 20px;">
<label style="width:9%;" for="9009" class="page3-suggested-cat-label" >BoQ</label>
<div class="input-group" style="margin-top: 10px;
width: 70%;">
<span class="form-control"></span>
<span class="input-group-btn">
<span class="btn btn-primary" onclick="$(this).parent().find('input[type=file]').click();">Browse</span>
<input name="file|90009|107" id="file|9009"
value="" onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[\\|/]/).pop());"
style="display: none;" type="file">
</span>
</div>
</br> <center><h2><strong>OR</strong></h2></center>
</div>
</div>
<div class="next-btn-wrap"><div class="cf"></div>
<div class="back-btn-wrap">
{{ Form::submit('Back',array('class' => 'back-btn', 'name' => 'back'))}}
</div>
<div class="save-btn-wrap">
{{ Form::submit('Save',array('class' => 'save-btn','name' => 'save'))}}
</div>
{{ Form::submit('Next',array('class' => 'next-btn','name' => 'next'))}}
</div>
{{ Form::close()}}
and in my controller I am using following code to get the data
$aa = Input::except(array('_token','back','save','next'));
//dd($aa);
foreach ($aa as $key=>$value){
$ids = explode("|",$key);
if(isset($ids[0]) && $ids[0]=="file" ){
$userid = Session::get('userid');
$event = Session::get('event');
$fileTblObj = new fileHandler();
$ans = Answer::find($ids[2]);
if(isset($aa[$key])){
//dd($aa[$key]);
if(Input::file($key)->isValid()) {
$destinationPath = 'app/uploads/'.$event.'/'.$userid.'/'.$pageNo ; // upload path
$extension = Input::file($key)->getClientOriginalExtension(); // getting image extension
$name = Input::file($key)->getClientOriginalName();
$curFilesize = Input::file($key)->getClientSize();
$mime =Input::file($key)->getMimeType();
if (!File::exists($destinationPath."/boq-".$name)){
//creating details for saving inthe file_handler Table
$fileTblObj->user_id = $userid;
$fileTblObj->eventName = $event ;
$fileTblObj->fileName = "boq-".$name;
$fileTblObj->formPage =$pageNo ;
$fileTblObj->filePath = $destinationPath."/";
$fileTblObj->mime= $mime;
$ans->answer_text = 'Yes';
Input::file($key)->move($destinationPath, "boq-".$name); // uploading file to given path
//Input::file($key)->move($boqPath, $boqname); // uploading file to given path
//Save filedetails
$fileTblObj->save();
$ans->save();
Session::flash('success', 'Upload successfully');
}else if(File::size($destinationPath."/".$name) != $curFilesize){
$fileDtls = $fileTblObj->where('uid',$userid)->where('fileName',$name)->where('formPage',$pageNo)->first();
Input::file($key)->move($destinationPath, $name);
$ans->answer_text = 'Yes';
$ans->save();
$fileTblObj->where('id',$fileDtls->id)->update(array('updated_at'=>date("Y-m-d h:m:s",time())));
}
//return Redirect::to('upload');
}
}
else
{
if($ans->answer_text =='')
{
$ans->answer_text = 'No';
$ans->save();
}
}
}
My problem is I am not able to get the file details on the back-end
the if statement
if(isset($ids[0]) && $ids[0]=="file" ){
}
is always false .
Any Idea How I can fix this. I also tried changing the The FOrm function to
{{ Form::open(array('files' => true)) }}
Still its not showing the file details
To send a file, I personally use this methods.
View:
{!! Form::open(array('action' => 'TestController#store', 'method' => 'POST', 'files'=>true)) !!}
{!! Form::file('thefile') !!}
{!! Form::submit('Save', array('class' => 'btn')) !!}
{!! Form::close() !!}
Controller:
$thefile = Input::file('thefile');
Hope this helps!

can't access the variable i passed from controller to my view in laravel 4.2

i have a view that contains a form. the form's url is the address of view that the form is in it.
in controller i pass a variable to the view when the user hit the button in the form.
but my view has an error says the variable i passed to it is undefined.
here is my code
my view:
#extends('layouts.master')
#section('content')
<?php
$category = Category::lists('name','name');
$priority = Priority::lists('name','name');
$lesson = Lesson::lists('name','name');
$count = 1;
?>
{{ Form::open(array('action' => 'createQuizController#find', 'method' => 'POST', 'id' => 'search_question')) }}
<div>
{{ Form::label('quiz_cat', 'نام دسته بندی') }}
{{ Form::select('quiz_cat', array('/'=>'انتخاب کنید')+$category, null, ['id' => 'cat_select']) }}
</div>
<div>
{{ Form::label('quiz_less','نام درس') }}
{{ Form::select('quiz_less',$lesson, null, ['id' => 'les_select']) }}
</div>
<div>
{{ Form::label('quiz_prio','سطح سوال') }}
{{ Form::select('quiz_prio',array('/'=>'انتخاب کنید')+$priority, null, ['id' => 'prio_select']) }}
</div>
<div>
{{Form::label('date_start','تاریخ شروع')}}
{{Form::input('date','date_start',null,array('id' => 'date_start'))}}
</div>
<div class='form-group'>
{{ Form::submit('جستجو', ['class' => 'btn btn-primary']) }}
</div>
{{ Form::close() }}
<iframe width="690px" height="300px" scrolling="yes">
{{ Form::open(array('method' => 'POST', 'id' => 'add_question')) }}
<div class="col-lg-10 col-lg-offset-1">
<div class="table-responsive" id="question_table">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ردیف</th>
<th>عنوان سوال</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($res as $quiz)
<tr>
<td align="center" width="100px">
<?php echo $count++; ?>
</td>
<td align="center" width="200px">{{ $quiz->title }}</td>
<td align="center" width="200px"><input type="checkbox" name="select_question[]" id="{{ $quiz->lesson_id }}" value="{{ $quiz->id }}"></td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
{{ Form::submit('افزودن', ['class' => 'btn btn-primary']) }}
{{ Form::close() }}
</iframe>
#stop
my controller:
<?php
class createQuizController extends BaseController {
public function find()
{
$prio = Input::get('quiz_prio');
$res1 = DB::select("select id from priority pr where '$prio' = pr.name");
$r1 = $res1[0]->id;
$cat = Input::get('quiz_cat');
$res2 = DB::select("select id from categories cat where '$cat' = cat.name");
$r2 = $res2[0]->id;
$les = Input::get('quiz_less');
$res3 = DB::select("select id from lesson less where '$les' = less.name");
$r3 = $res3[0]->id;
$sdate = Input::get('date_start');
$res = DB::select("select * from quiz where categories_id='$r2' and lesson_id='$r3' and priority_id='$r1' and date_start='$sdate'");
return View::make('cquiz')->with('res',$res);
}
public function addQuestion()
{
$a = array();
$a[] = Input::get('select_question');
var_dump($a[]);
/*foreach($a as $b) {
$c = DB::select("select name from lesson where '$b'=id" );
var_dump($c);
}*/
}
}
my route:
Route::post('/cquiz/','createQuizController#find');
Route::post('/addQuestion/','createQuizController#addQuestion');
try this:
return View::make('cquiz')->withRes($res);
and in the view you can access '$res' (or {{ $res }} etc)

Categories