Hello I have row in a database table have an id and name and etc.. and active = 1
I want in blade.php file when someone click a button it change into 0 in 1 click
What I tried is {{$referral_detail->update('active', 1)}}
And
{{$referral_detail->IDT->where('active', 0)->update('active', 1)}}
Function in Controller is
public function DriverReferAll()
{
$query = DriverReferralDiscount::where([['referral_driver_id', '!=', 0],
['referral_sender_id', '!=', 0], ['active', '<>', 1]
]);
$referral_details = $query->paginate(25);
return view('merchant.driver.driver_referall', compact('referral_details', 'query'));
}
I got it thedit('{{$referral_detail->IDT->update(['active' => 1])}}')
and function
function thedit(a) {
$("input:submit").val(a);
}
But when I do it , it change the first 2 column not only 1 tho I put the specific id any idea?
its in onClick""
<span onClick=" thedit('{{$referral_detail->IDT->update(['active' => 1])}}')
" data-target="#addMoneyModel"
data-toggle="modal" id="{{ $referral_detail->GetterDriver->id }}"><a
data-original-title="Add Money"
data-toggle="tooltip"
id="{{ $referral_detail->GetterDriver->id }}" data-placement="top"
class="btn text-white btn-sm btn-success menu-icon btn_detail action_btn"> <i
class="fa fa-money-bill"></i> </a></span>
For that you must create a link in your blade template when that link is clicked It must have an href which point to the laravel route which will perform the update of your active state.
<a href="{{ route('your_route_name', ['id' => $referral_detail->id]) }}>Change</a>
the route can be define like this
Route::get('/route_path/{id}', 'ControllerName#action_name')->name('route_name');
Or If you want the browser to not refresh you can perform and Ajax
Related
I am currently building a feature where a user can select an option from a select box, once an item is selected you can click a button which hits my endpoint which submits and stores it.
However if i dont select anything but then click the button it just hits a 404 page on the same endpoint.
Blade
Below contains the blade syntax for the select box and button.
<div class="row align-items-center">
<div class="col-md">
<small class="text-success">
please select one of the teams below to store your preference.
</small>
{!! Form::open(['route' => ['team.create.link', $team->id],'method' => 'post', 'class' => 'needs-validation','novalidate', null]) !!}
{!! Form::select('teams[]', $teams, '', ['class' => 'custom-select', 'multiple'], ['required']) !!}
<button class="btn btn-primary btn-sm mt-3 float-right">
<i class="fas fa-fw fa-plus-circle mr-2"></i>
Add</button>
{!! Form::close() !!}
</div>
</div>
Method
Below is the method used for storing the new input within the pivot table.
public function link(string $teamId)
{
$team= Team::findOrFail($teamId);
$links = Input::get('teams');
$link = Team::findOrFail($links);
$team->links()->attach($link);
session()->flash('success', 'Link Added.');
return back();
}
Help
How would i modify this so that the button cant be clicked and returns a required error if an option isnt selected? i've tried adding ['required'] to the form::select but i had no luck with that.
Can anyone push me in the right direction?
You can validate your Reqeust with $this->validate
use Illuminate\Http\Request;
public function link(Request $reqeust, string $teamId)
{
$request->validate([
'teams' => 'required',
]);
$team = Team::findOrFail($teamId);
$links = Input::get('teams');
$link = Team::findOrFail($links);
$team->links()->attach($link);
session()->flash('success', 'Link Added.');
return back();
}
Take a look at the official Laravel Documentation for Validation
In Laravel-5.8 application, a form is submitted and notification is submitted through:
$userId = Auth::user()->id;
'actionURL' => route('appraisal.appraisal_goals.manager_employee_goal', ['id'=>$userId]),
This correctly send notification:
[![notification][1]][1]
route:
Route::group(['prefix' => 'appraisal', 'as' => 'appraisal.', 'namespace' => 'Appraisal', 'middleware' => ['auth']], function () {
Route::get('appraisal_goals/goal_review', 'AppraisalGoalsController#goal_review')->name('appraisal_goals.goal_review');
Route::get('appraisal_goals/manager_employee_list', 'AppraisalGoalsController#manager_employee_list')->name('appraisal_goals.manager_employee_list');
Route::get('appraisal_goals/manager_employee_goal/{id?}', 'AppraisalGoalsController#manager_employee_goal')->name('appraisal_goals.manager_employee_goal');
Route::get('appraisal_goals/manager_employee_goal_list/{id?}', 'AppraisalGoalsController#manager_employee_goal_list')->name('aappraisal_goals.manager_employee_goal_list');
});
manager_employee_goal.blade
<td>
#if(in_array($goal->is_approved, [1, 2, 3]))
<a class="btn btn-xs btn-primary" href="{{ route('appraisal.appraisal_goals.manager_employee_goal_list', ['id'=>$goal->id]) }}">
{{ trans('global.view') }}
</a> #endif #if(in_array($goal->is_approved, [1]))
<a class="btn btn-xs btn-info" data-toggle="modal" data-target="#comment{{ $goal->id }}" data-original-title="Comment">Comment</a> #endif
</td>
When the user clicks on the button on the notification as shown in the diagram, it suppose to redirect to:
Route::get('appraisal_goals/manager_employee_goal/{id?}', 'AppraisalGoalsController#manager_employee_goal')->name('appraisal_goals.manager_employee_goal');
But I got error 500 and the browser url has:
http://localhost:8888/myapp/appraisal/appraisal_goals/manager_employee_goal/470
The the Log has this error:
2020-10-22 17:29:51] production.ERROR: Route [appraisal.appraisal_goals.manager_employee_goal_list] not defined. (View: C:\xampp\htdocs\pmyapp\resources\views\appraisal\appraisal_goals\manager_employee_goal.blade.php) {"userId":469,"exception":"[object] (ErrorException(code: 0): Route [appraisal.appraisal_goals.manager_employee_goal_list] not defined. (View: C:\xampp\htdocs\myapp
esources\views\appraisal\appraisal_goals\manager_employee_goal.blade.php) at C:\xampp\htdocs\myapp\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php:388, InvalidArgumentException(code: 0): Route [appraisal.appraisal_goals.manager_employee_goal_list] not defined. at C:\xampp\htdocs\myapp\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php:388)
I didn't call:
appraisal.appraisal_goals.manager_employee_goal_list
Why is it coming up and how do I resolve this error?
Thanks
I am using Yarja datatables for quite a complex table set and also have the ajax part returning two buttons:
{
$user = Auth::user();
$cl = $user->client_id;
$jb = DB::table('job')
->join('job_status', 'job.jobStatus_id', '=', 'job_status.id')
->join('customers', 'job.customer_id', '=', 'customers.id')
->join('users', 'job.operative_id', 'users.id')
->where('job.client_id', $cl)
->select(['job.id as id', 'job_status.status as status', 'job.customer_id as customer_id', 'customers.customer as customer', 'users.name as operative','job.address as address','job.postcode as postcode','job.slug as slug','job_status.id as jobStatusID'])
->get();
return Datatables::of($jb)
->addColumn('action', function($pubs){
$btn = '<div style="float:right">
<i class="fas fa-book" ></i><i class="fas fa-edit" ></i></div>';
return $btn;
})
->make(true);
}
This works fine but now I want to add an action to the buttons, initially the edit, which is the route and the id of the row.
As you can see I have replaced the # with the route so I have
"admin\jobView"
but I cannot seem to work out a way of adding a field from the query (specifically jb->id) so that the action would be something like
admin\jobView\123
Just can't seem to get it and would greatly appreciate some help!
$pubs should contain your job, so you should be able to use $pubs->id, to get the job id.
What I would do though is replace this giant string with a view so it becomes easier to maintain:
return Datatables::of($jb)
->addColumn('action', function($job) {
return (string)view('admin.jobs.action', compact('job'));
})
->rawColumns(['action'])
->make(true);
Create a view, admin/jobs/action.blade.php for example:
<div style="float:right">
<a href="{{ route('admin.jobview', $job->id) }}" class="btn btn-outline-secondary btn-xs" title="show details" style="margin-right:.5em;font-size:.75em">
<i class="fas fa-book"></i></a>
<a href="{{ route('admin.jobview', $job->id) }}" class="btn btn-outline-secondary btn-xs" title="show details" style="margin-right:.5em;font-size:.75em">
<i class="fas fa-edit"></i>
</a>
</div>
When I make search and I get the search results, I try to delete a record , its deleted show the message that successfully deleted but after I get the error throw new MethodNotAllowedHttpException($others);
public function destroy($id)
{
$id = Hashids::decode($id);
$id = implode(',', $id);
$sub = Subs::find($id);
$sub->delete();
return response()->json([
'success' => "Subscription Plan Deleted successfully.",
'tr' => 'tr_' . $id,
]);
}
The routes:
Route::post('/subscriptions/search/results','SubsController#searchSubs');
Route::get('/subscriptions/restore/{id}', 'SubsController#restore');
The link:
<a href="{{action('SubsController#destroy', Hashids::encode($sub['id']))}}" class="btn btn-danger btn"
data-tr="tr_{{$sub['id']}}" data-toggle="confirmation" data-btn-ok-label="Delete" data-btn-ok-icon="fa fa-remove"
data-btn-ok-class="btn btn btn-danger" data-btn-cancel-label="Cancel"
data-btn-cancel-icon="fa fa-chevron-circle-left" data-btn-cancel-class="btn btn btn-default"
data-title="Are you sure you want to delete ?" data-placement="left" data-singleton="true">Delete </a>
Route::resource('subscriptions','SubsController');
creates a destroy method which requires request type DELETE.
e.g.
Route::delete(subscriptions/destroy','SubsController#destroy');
to do so you will have to make a form and send a DELETE request like below.
<form action="{{ route('routename',$parameter) }}" method="POST">
{{csrf_field()}}
{{method_field('DELETE')}}
<button type="submit" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill"> <i class="glyphicon glyphicon-trash"></i></button>
</form>
check your route in console by
php artisan route:list
If you cant do that then:
remove destroy method from resource like this:
Route::resource('subscriptions','SubsController')->except('destroy');
Now it will not include destroy method. Now you can make your own route of get request and send id of record to delete it
relation of customer with job
public function customer() {
return $this->belongsTo('App\Customer','customerid');
}
public function jobs(){
return $this->hasMany('App\Job','customerid');
}
in controller
protected function getJobs(){
$jobs = Job::Join('customer','jobs.customerid','=','customer.id')
->select(array('jobs.id','customer.firstname','customer.lastname','jobs.jobstatus','jobs.trialdate','jobs.deliverydate'));
return Datatables::of($jobs)
->addColumn('action', '<a class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="top" title="Edit" href="{{ URL::to(\'updatejob/\'.$id) }}"><i class="fa fa-pencil"></i></a>')
->make();
}
it throw following error
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'order clause' (SQL: select `jobs`.`id`, `customer`.`firstname`, `customer`.`lastname`, `jobs`.`jobstatus`, `jobs`.`trialdate`, `jobs`.`deliverydate` from `jobs` inner join `customer` on `jobs`.`customerid` = `customer`.`id` order by `0` asc limit 10 offset 0)
i'm stuck in this issue from 2 day please help me to get out from this
I think you missed "order by" in your query, try this :
protected function getJobs(){
$jobs = Job::Join('customer','jobs.customerid','=','customer.id')
->select(array('jobs.id','customer.firstname','customer.lastname','jobs.jobstatus','jobs.trialdate','jobs.deliverydate'))
->orderBy('customer.lastname')->get();
return Datatables::of($jobs)
->addColumn('action', '<a class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="top" title="Edit" href="{{ URL::to(\'updatejob/\'.$id) }}"><i class="fa fa-pencil"></i></a>')
->make();
}
I simply update the composer ->php composer.phar update
Its working fine now
Thanks