Adding Data to the multiple column in laravel 5.7 - php

Hi I am working on a project and I need to do some addition while working on a table.
like I have to fill the three fields and change the status to 2 using checkbox Array. I tried it all but with no luck. Kindly look into it and Let me know the changes I can Do.
My Model CustomerLoad.php is
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CustomerLoad extends Model
{
protected $fillable = [
'driver_id',
'vehicle_id',
'company_id',
'customer_id',
'package_type',
'from',
'to',
'in_mile',
'weight',
'height',
'width',
'length',
'rate',
'duration_text',
'ticket_number',
'status_id'
];
public function status()
{
return $this->belongsTo('App\Status');
}
}
My Controller for creating the page is Like this
public function create()
{
$csloads = CustomerLoad::paginate(4);
$driver = Driver::pluck('name', 'id')->all();
$vehicle = Vehicle::pluck('vin', 'id')->all();
$company = Company::pluck('name', 'id')->all();
return view('customerload.create', compact('csloads', 'driver', 'vehicle', 'company'));
}
for storing it
public function updatecsloads(Request $request)
{
if(isset($request->update_all) && !empty($request->checkBoxArray)){
$csloads = CustomerLoad::findOrFail($request->checkBoxArray);
foreach($csloads as $csload){
$input = $request->all();
dd($input);
// $csload->update($input);
}
// return redirect()->back();
// } else {
// return redirect()->back();
}
}
My View is like
<div class="card">
<div class="card-header card-header-rose card-header-text">
<div class="card-ttle">
<h4 class="card-text">Allocate Loads</h4>
</div>
</div>
<div class="card-body">
{!! Form::model(['method' => 'PATCH', 'action' => ['CustomerLoadsController#updatecsloads']]) !!}
<div class='form-group'>
{!! Form::select('checkBoxArray', ['' => 'Allocate'], null, ['class' => 'selectpicker form-control', 'data-style'=>'btn btn-link', 'id'=>''])!!}
</div>
<div class='form-group'>
{!! Form::submit('Allocate Loads', ['class'=>'btn btn-rose pull-right']) !!}
</div>
#if(count($csloads) > 0)
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th><input type="checkbox" id="options"></th>
<th>Driver Name</th>
<th>Company Name</th>
<th>Vehicle Vin Number</th>
<th>Origin</th>
<th>Destination</th>
<th>Package Type</th>
<th>Dimensions</th>
<th>Weight</th>
</tr>
</thead>
<tbody>
#foreach($csloads as $csload)
#if($csload->status_id == 1)
<tr>
<td>{‌{$csload->id}}</td>
<td><input class="checkBoxes" type="checkbox" name="checkBoxArray[]" value="{‌{$csload->status ? $csload->status->id == 2 : $csload->status->id == 1}}"></td>
<td>{!! Form::select('driver_id', ['' => 'Choose Driver Name'] + $driver, null, ['class' => 'selectpicker form-control', 'data-style'=>'btn btn-link', 'id'=>'exampleFormControlSelect1'])!!}</td>
<td>{!! Form::select('company_id', ['' => 'Choose Company Name'] + $company, null, ['class' => 'selectpicker form-control', 'data-style'=>'btn btn-link', 'id'=>'exampleFormControlSelect1'])!!}</td>
<td>{!! Form::select('vehicle_id', ['' => 'Choose Vehicle Vin Number'] + $vehicle, null, ['class' => 'selectpicker form-control', 'data-style'=>'btn btn-link', 'id'=>'exampleFormControlSelect1'])!!}</td>
<td>{‌{$csload->from}}</td>
<td>{‌{$csload->to}}</td>
<td>{‌{$csload->package_type}}</td>
<td>{‌{$csload->length}}x{‌{$csload->width}}x{‌{$csload->height}}</td>
<td>{‌{$csload->weight}}</td>
</tr>
#endif
#endforeach
</tbody>
</table>
</div>
#else
<h1 class="text-center">No Loads Found</h1>
#endif
{!! Form::close() !!}
</div>
</div>
</div>
I am struck in the project kindly answer the question as soon as you can I shall be really obliged.
Thanks in advance
From Munish Rana
Love your Work

change 'method' => 'PATCH' to 'POST'
and add {{ method_field('PATCH') }} to form field like this
<form method="POST" action="your url" >
{{csrf_field()}}
{{ method_field('PATCH') }}
</form>

Related

How to incremented in table on button click laravel

I have Home.blade.php in which if I click vote button it should increment the count in candidate table.
home.blade.php
#foreach ($file as $show)
<div class="col-md-3" style="margin-bottom: 20px;">
<div class="card">
<img src="{{$show->image}}" style="width:100%">
<div class="card-body">
<h5 class="title">President</h5>
<p class="card-text">Name : {{$show->name}}</p>
<button>VOTE</button>
</div>
</div>
</div>
#endforeach
homecontroller
public function Count(){
DB::table('candidate')->increment('count');
return view('/home')->with('success', 'voted');
}
Route
Route::get('/home','Homecontroller#Count');
Please help me to increment the count, if not this method is there any other method to do the same.
Yes, there is a better way.
Add this to Your web.php
Route::put('/votesUp/{vote}', 'HomeController#upVote')->name('votes.upVote');
Route::put('/votesDown/{vote}', 'HomeController#downVote')->name('votes.downVote');
in your view list thats is index.blade.php add this two buttons
FORM BUILDER WAY
#foreach($candidates as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{!! $item->name !!}</td>
<td>{!! Form::model($item, ['method' => 'PUT', 'route' => ['votes.upVote', $item->id ] ,'enctype'=>'multipart/form-data' ]) !!}
{!! Form::submit( 'Up Vote', ['class' => '', 'name' => 'submitbutton', 'value' => 'upvote'])!!}
{!! Form::close() !!}</td>
<td>{!! Form::model($item, ['method' => 'PUT', 'route' => ['votes.downVote', $item->id ] ,'enctype'=>'multipart/form-data' ]) !!}
{!! Form::submit( 'Down Vote', ['class' => '', 'name' => 'submitbutton', 'value' => 'upvote'])!!}
{!! Form::close() !!}</td>
</tr>
#endforeach
HTML WAY
#foreach($candidates as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{!! $item->name !!}</td>
<td>
<form method="post" action="{{ route('votes.upVote', $item->id) }}">
#method('PUT')
#csrf
<input class="" name="submitbutton" value="Up Vote" type="submit">
</form>
<form method="post" action="{{ route('votes.downVote', $item->id) }}">
#method('PUT')
#csrf
<input class="" name="submitbutton" value="Down Vote" type="submit">
</form>
</td>
</tr>
#endforeach
I am Considering Your model as Candidate so add this to HomeController
ELOQUENT way
public function upVote(Request $request, $id)
{
Candidate::find($id)->increment('votes_count', 1);
return redirect()->back();
}
public function downVote(Request $request, $id)
{
Candidate::find($id)->decrement('votes_count', 1);
return redirect()->back();
}
DB Facade Way
public function upVote(Request $request, $id)
{
\DB::table('candidates')->where('id','=',1)->increment('votes_count', 1);
return redirect()->back();
}
public function downVote(Request $request, $id)
{
\DB::table('candidates')->where('id','=',1)->decrement('votes_count', 1);
return redirect()->back();
}
Explained:
When You click on the upvote button filed votes_count in candidates table will be
incremented by 1
When You click on the downvote button filed votes_count in candidates table will be decremented by 1
EDIT FOR undefined variable candidate
Find this line
#foreach($candidates as $item)
And Replace with
#foreach ($file as $item)
FIX FOR
Class App\Http\Controllers\HomeController does not exist
From
Route::put('/votesUp/{vote}', 'HomeController#upVote')->name('votes.upVote');
Route::put('/votesDown/{vote}', 'HomeController#downVote')->name('votes.downVote');
TO
Route::put('/votesUp/{vote}', 'Homecontroller#upVote')->name('votes.upVote');
Route::put('/votesDown/{vote}', 'Homecontroller#downVote')->name('votes.downVote');
Your Controller Class
Homecontroller
but i have wrongly written as
HomeController
Make sure your column count is integer type in migration
And:
You are writing it in wrong way
<button>VOTE</button>
change it to
<button>VOTE</button>
The vote button should be like this:
<button>VOTE</button>
With the functionalities like Upvote and Downvote as answered nicely by #manojkiran-a above, I would also add throttling. Now a days it is easy to create a bot which will send upvote requests even when you are using csrf token.
I would add :
'middleware' => 'throttle:5'
Which will allow only 5 requests per minute per IP address. Not entirely preventing it but making it little harder.
Route::put('/votesUp/{vote}', 'Homecontroller#upVote')->middleware('throttle:5')->name('votes.upVote');
Route::put('/votesDown/{vote}', 'Homecontroller#downVote')->middleware('throttle:5')->name('votes.downVote');

Updating multiple records using Laravel 5.3 model binding

I am pulling multiple records from MySQL and looping through model binding and filling all the input fields with some data.
Now, I may change 2 or 10 or all 26 fields and hit update button. I want to update all the records. Now, I don't know how $id works here? usually I update single record and I have $id which I can find and update only that field.
But that's not the case here. I am pulling 13 records(or 26 fields). 13 field_1 and 13 field_2. How to update all?
mycode
Database
Table
-id
-name
-field1 (updating this one)
-field2 (updating this one)
Routes
Route::get('/cat' , 'AdminController#cat');
Route::patch('/cat/{$id}/update','AdminController#cat_update');
Controller
public function cat(){
$cattfs = Catf::all();
return view('/cat',compact('cattfs'));
}
public function cat_update(Request $request, $id) // id = 1
{
$rules = array(
'field1' => 'required',
'field2' => 'required'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect()->back()->withErrors($validator);
} else {
$cat = Cattf::find($id); //This wont work :/
$cat ->field1 = Input::get('field1');
$cat ->field2 = Input::get('field2');
$cat ->save();
return redirect('/cat');
}
}
Views
<div class="col-md-6" style="background-color:#fff">
<table class="table table-hover">
<thead>
<tr>
<th style="text-align: center">Product</th>
<th style="text-align: center">Pr</th>
<th style="text-align: center">Co</th>
</tr>
</thead>
<tbody>
#foreach ($cattos as $catto)
{!! Form::model($catto,[ 'method' =>'PATCH', 'url' => ['/cat/.$catto->id./update']]) !!}
<tr>
<td>{{$catto->name}}</td>
<td> {!! Form::text('field1' ,null , ['class'=>'form-control']) !!}</td>
<td> {!! Form::text('field2' ,null , ['class'=>'form-control']) !!}</td>
</tr>
#endforeach
<td colspan="3">
{!! Form::submit('UPDATE', ['class'=>'btn btn-primary btn-block']) !!}
{!! Form::close() !!}
</td>
</tr>
</tbody>
</table>
</div>
snapshot of the form
I don't think you can do this with Model binding (correct me if I'm wrong someone).
What you can instead do is generate an array of data to post to your controller.
For example:
{!! Form::open(['route' => 'catupdate']) !!}
#foreach ($cattos as $catto)
<tr>
<td>{{$catto->name}}</td>
<td>{!! Form::text('categories['.$catto->id.'][field1]', null, ['class'=>'form-control']) !!}</td>
<td>{!! Form::text('categories['.$catto->id.'][field2]', null, ['class'=>'form-control']) !!}</td>
</tr>
#endforeach
{!! Form::close() !!}
You should then receive an array in your controller, which you can loop around and update each record.
public function catupdate()
{
$categories = request()->input('categories');
foreach($categories as $id => $values) {
$cat = Cattf::find($id);
$cat->field1 = $values['field1'];
$cat->field2 = $values['field2'];
$cat->save();
}
}
You can then also validate the array by doing the following in your Request file
public function rules()
{
return [
'categories.*.field1' => 'required',
'categories.*.field2' => 'required'
];
}
this is untested and is an example demonstrating the concept

Laravel 5.4 change user role

I trying make changing role in my panel admin. But when i made it my form dont sending post request. Now only working showing user role. I cant fix it becouse when i click button to switch i dont get any error and role is not changing.
I use HttpRequester when i use url /admin/change its showing this error:
MethodNotAllowedHttpException in RouteCollection.php line 233
There is my code:
View:
#extends('layouts.app')
#section('content')
<h2>Panel Admina</h2>
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-body">
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Imię</th>
<th>Nazwisko </th>
<th>E-mail </th>
<th>Nr.tele </th>
<th>Użytkownik </th>
<th>Moderator </th>
<th>Admin </th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<form action="{{route('change')}}" method="post">
{{ csrf_field() }}
<td>{{ $user->id }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->lastname }}</td>
<td>{{ $user->email }}<input type="hidden" name="email" value="{{ $user->email }}"></td>
<td>{{ $user->phonenumber }}</td>
<td><input type="checkbox" {{ $user->hasRole('User') ? 'checked' : '' }} name="role_user"/></td>
<td><input type="checkbox" {{ $user->hasRole('Moderator') ? 'checked' : '' }} name="role_moderator"/></td>
<td><input type="checkbox" {{ $user->hasRole('Admin') ? 'checked' : '' }} name="role_admin"/></td>
<td><input type="submit" class="btn btn-default btn-sm" value="Przydziel rolę"></td>
</form>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
#endsection
Controller:
public function change(Request $request)
{
$user = User::where('email', $request['email'])->first();
$user->roles()->detach();
if ($request['role_user']) {
$user->roles()->attach(Role::where('name', 'User')->first());
}
if ($request['role_moderator']) {
$user->roles()->attach(Role::where('name', 'Moderator')->first());
}
if ($request['role_admin']) {
$user->roles()->attach(Role::where('name', 'Admin')->first());
}
return redirect()->back();
}
Routing:
Route::get('/admin', [
'uses' => 'AdminController#index',
'middleware' => 'roles',
'roles' => ['Admin']
]);
Route::post('/admin/change', [
'uses' => 'AdminController#change',
'as' => 'change',
'middleware' => 'roles',
'roles' => ['Admin']
]);
I really dont know how i can resolve my problem.
try to pass the user id to your route and your form action and instead of post make it put for example:
<form action="{{route('change', $user->id)}}" method="post">
and in your route:
Route::put('/admin/change/{id}', [
'uses' => 'AdminController#change',
'as' => 'change',
'middleware' => 'roles',
'roles' => ['Admin']
]);
and in your controller:
public function change(Request $request, $id)

got error when show data from other table laravel 5.2

i have 2 tables.
users (name, username, email, password, remember_token)
dosen (iddosen, namedosen, address, phonenumber)
i want to show data from 2 tables in 1 view.
my User model :
public function profildosen()
{
return $this->belongsTo('App\Dosen');
}
Dosen model :
public function user()
{
return $this->hasOne('App\User');
}
view :
#foreach($dosen as $key => $value)
<strong>Kode Dosen :</strong> {{ $value->profildosen->iddosen }}<br>
<strong>Nama :</strong> {{ $value->profildosen->namedosen}}<br>
<strong>Alamat :</strong> {{ $value->profildosen->address}}<br>
<strong>No HP :</strong> {{ $value->phonenumber}} <br>
<strong>Email :</strong> {{ $value->email }}<br>
#endforeach
method :
$dosen = User::paginate(5);
return view('admin/dosen.index', compact('dosen'));
and got error :
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dosen.id' in 'where clause' (SQL: select * from `dosen` where `dosen`.`id` is null limit 1) (View: D:\XAMPP\htdocs\infodosenku\resources\views\admin\dosen\index.blade.php)
what is the right method ?
UPDATE
Scheme Database
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('username');
$table->string('email')->unique();
$table->string('password', 60);
$table->boolean('admin')->default(0);
$table->rememberToken();
$table->timestamps();
});
Schema::create('dosen', function (Blueprint $table) {
$table->string('id');
$table->string('user_id');
$table->string('nipy');
$table->string('namadosen');
$table->string('alamatdosen');
$table->integer('notelpdosen');
$table->timestamps();
});
Route :
Route::resource('/admin/dosen', 'AdminController',
['except' => ['show']]);
Controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Request;
use App\Http\Requests;
use App\Http\Requests\CreateDosenRequest;
use App\Dosen;
use App\User;
use Illuminate\Support\Facades\Input;
use DB;
class AdminController extends Controller
{
public function index()
{
// ambil semua data dosen
$dosen = User::paginate(5);
return view('admin/dosen.index', compact('dosen'));
}
public function create()
{
return view('admin/dosen.create');
}
public function store(CreateDosenRequest $request)
{
$user = User::create([
'name' => $request->input('name'),
'username' => $request->input('username'),
'email' => $request->input('email'),
'password' => bcrypt($request->input['password']),
'admin' => $request->input('admin')
]);
$dosen = Dosen::create([
'id' => $request->input('iddosen'),
'nipy' => $request->input('nipy'),
'namadosen' => $user->name,
'user_id' => $user->id,
'alamatdosen' => $request->input('alamatdosen'),
'notelpdosen' => $request->input('notelpdosen'),
]);
return redirect('admin/dosen')->with('message', 'Data berhasil ditambahkan!');
}
public function show($id)
{
$dosen = User::find($id);
return view('admin/dosen/show', compact('dosen'));
}
public function edit($id)
{
$dosen = User::find($id);
return view('admin.dosen.edit', compact('dosen'));
}
public function update($id)
{
$dosenUpdate = Request::all();
$dosen = User::find($id);
$dosen->update($dosenUpdate);
return redirect('admin.dosen')->with('message', 'Data berhasil diubah!');
}
public function destroy($id)
{
User::find($id)->delete();
return redirect('admin.dosen')->with('message', 'Data berhasil dihapus!');
}
}
And my View :
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Daftar Dosen</div>
<div class="panel-body">
<form class ="form-inline" action="{{ URL('/dosen/hasil/') }}" action="GET">
<div class="form-group">
<label for="cari">Cari Dosen </label>
<input type="text" class="form-control" id="cari" name="cari" placeholder="Masukan Nama Dosen">
</div>
<input class="btn btn-primary" type="submit" value="Cari">
</form><br>
<table class="table table-striped table-bordered">
<thead>
<tr>
<td>Nama</td>
<td>username</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
#foreach($dosen as $key => $value)
<tr>
<td>{{ $value->name }}</td>
<td>{{ $value->username}}</td>
<td>
{!! Form::open(['url' => 'dosen/' . $value->id . '/edit', 'style'=>'display:inline-block']) !!}
{!! Form::hidden('_method', 'GET') !!}
{{ Form::button('<i class="fa fa-pencil-square-o"></i>', ['type' => 'submit', 'class' => 'btn btn-warning', 'title' => 'Ubah'] ) }}
{!! Form::close() !!}
<button title="Tampilkan" type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal-{{ $value->id }}"><i class="fa fa-share"></i></button>
<!-- Modal -->
<div class="modal fade" id="myModal-{{ $value->id }}" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">{{ $value->namadosen }}</h4>
</div>
<div class="modal-body" style="overflow:auto;">
<strong>Kode Dosen :</strong> {{ $value->dosen->id }}<br>
<strong>NIP/NIPY :</strong> {{ $value->nipy }}<br>
<strong>Nama :</strong> {{ $value->namadosen }}<br>
<strong>Alamat :</strong> {{ $value->alamatdosen }}<br>
<strong>No HP :</strong> {{ $value->notelpdosen }} <br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{!! Form::open(['url' => 'dosen/' . $value->id, 'style'=>'display:inline-block']) !!}
{!! Form::hidden('_method', 'DELETE') !!}
{{ Form::button('<i class="fa fa-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger', 'title' => 'Hapus'] ) }}
{!! Form::close() !!}
{!! Form::model($value, ['route' => ['admin.dosen.update', $value->id], 'method' => 'PUT']) !!}
</td>
</tr>
#endforeach
</tbody>
</table>
<h5><span class="label label-default">
Showing {!! $dosen->count() !!} results from total {!! $dosen->total() !!} results.
</span></h5>
<div> {!! $dosen->links() !!} </div>
</div>
</div>
</div>
</div>
</div>
#endsection
Dosen Model :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Dosen extends Model
{
protected $table = 'dosen';
protected $fillable = ['iddosen', 'namadosen', 'user_id', 'nipy', 'kodeprogdidosen','alamatdosen', 'notelpdosen', 'tempatlahirdosen', 'tanggallahirdosen', 'agamadosen', 'emaildosen', 'sandidosen', 'jkldosen', 'fotodosen'];
protected $casts = [
'iddosen' => 'varchar',
];
public function dosen()
{
return $this->belongsTo('App\Dosen');
}
}
User Model :
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name', 'username', 'email', 'password', 'admin',
];
/**
* The attributes excluded from the model's JSON form.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function profildosen()
{
return $this->belongsTo('App\Dosen');
}
}
From Laravel Docs
Eloquent determines the default foreign key name by examining the name
of the relationship method and suffixing the method name with _id.
Your function name is profiledosen so Laravel will assume that in your in your Dosen Table you have id field as primary identifier.
You can change it from iddosen to id only and then change your method name to
public function dosen()
{
return $this->belongsTo('App\Dosen');
}
Alternatively you can supply the custom primary key to your method like
public function profildosen()
{
return $this->belongsTo('App\Dosen', 'iddosen');
}
The reason is that you badly identify your table id a so instead of dosen.id you should use dosen.iddosen
So the query should be like this: select * from dosen where iddosen is null limit 1
Or you may to use Laravel Query Builder More.
But the most important thing is that you need to know on what columns you will join your tables.
Hope it will help

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