checkboxes and icons disappear on search - laravel

I am using livewire components but when begin typing in the search input field, the checkboxes and icons in the component disappear, and they only reappear after refreshing the page. What could be the cause of this behaviour?
Blade view
<div>
<div class="row">
<div class="col-md-12 grid-margin stretch-card">
<div class="card">
<div class="card-header">
<div class="d-flex justify-content-between align-items-center flex-wrap grid-margin">
<div>
<h4 class="mb-3 mb-md-0">User Roles</h4>
</div>
<div class="d-flex align-items-center flex-wrap text-nowrap">
<div class="form-inline">
<div class="input-group mr-2 mb-2 mb-md-0 d-md-non d-xl-flex">
<input type="text" wire:model="search" class="form-control" placeholder="Search role...">
</div>
<div class="input-group mr-2 mb-2 mb-md-0 mt-3 d-md-non d-xl-flex">
<select wire:model="sortAsc" class="form-control form-control-s mb-3">
<option value="1">Ascending</option>
<option value="0">Descending</option>
</select>
</div>
<div class="input-group mr-2 mb-2 mb-md-0 mt-3 d-md-non d-xl-flex">
<select wire:model="perPage" class="form-control form-control-s mb-3">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
</select>
</div>
</div>
<a href="{{ route('create-role') }}" class="btn btn-success btn-icon-text mr-2 mb-2 mb-md-0">
<i class="btn-icon-prepend" data-feather="plus"></i>
Add Role
</a>
<button wire:click="deleteRoles" type="button" class="btn btn-danger btn-icon-text mb-2 mb-md-0">
<i class="btn-icon-prepend" data-feather="trash-2"></i>
Delete Role
</button>
</div>
</div>
</div>
<div class="card-body">
#if (count($roles) > 0)
<div class="table-responsive">
<table id="dataTableExample" class="table">
<thead>
<tr>
<th></th>
<th>#</th>
<th>Display Name</th>
<th>Description</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach ($roles as $role)
<tr wire:key="{{ $role->name }}">
<td>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" wire:model="selectedRoles.{{ $role->id }}" class="form-check-input">
</label>
</div>
</td>
<td>{{ $role->id }}</td>
<td>{{ $role->display_name }}</td>
<td>{{ $role->description }}</td>
<td>{{ $role->created_at->diffForHumans() }}</td>
<td>
<a href="{{ route('edit-role', $role->name) }}" class="btn btn-primary btn-icon-text mr-2 mb-2 mb-md-0">
<i class="btn-icon-prepend" data-feather="edit-2"></i>
Edit
</a>
</td>
</tr>
#endforeach
</tbody>
</table>
<div>{{ $roles->links() }}</div>
</div>
#else
<p>No user roles found.</p>
#endif
</div>
</div>
</div>
</div>
</div>
Corresponding livewire component
<?php
namespace App\Http\Livewire\Roles;
use Livewire\Component;
use App\Models\Role;
use Livewire\WithPagination;
class Index extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public $selectedRoles = [];
public $search = '';
public $perPage = 10;
public $sortField = 'id';
public $sortAsc = true;
public function render()
{
return view('livewire.roles.index', [
'roles' => Role::search($this->search)
->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
->simplePaginate($this->perPage)
])
->extends('layout.master');
}
public function createRole(){
return view('livewire.roles.create')
->extends('layout.master');
}
public function deleteRoles(){
Role::destroy($this->selectedRoles);
}
}
What could be causing this issue?

try changing this lines, actually I use this like livewire documentation
'roles' => Role::where('someColumn','like','%'.$this->search.'%')
orWhere('anotherColumn','like','%'.$this->searchTerm.'%')
->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
->paginate($this->perPage)

Related

insert data not working perfectly in laravel 8

Here I am doing l laravel CRUD operation.
I have a table named scores.
Schema::create('scores', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('match_id');
$table->unsignedBigInteger('team_id');
$table->unsignedBigInteger('player_id');
$table->unsignedBigInteger('scoreupdate_id');
$table->unsignedBigInteger('outby_id');
$table->timestamps();
$table->foreign('match_id')->references('id')->on('matchhs')->onDelete('cascade');
$table->foreign('team_id')->references('id')->on('teams')->onDelete('cascade');
$table->foreign('player_id')->references('id')->on('players')->onDelete('cascade');
$table->foreign('scoreupdate_id')->references('id')->on('scoreupdates')->onDelete('cascade');
$table->foreign('outby_id')->references('id')->on('scoreupdates')->onDelete('cascade');
});
Where I want to store data from the different tables so I did this with my Score.php model
class Score extends Model
{
use HasFactory;
use HasFactory;
protected $fillable =['team_id','match_id','player_id','scoreupdate_id','outby_id','out_type',
'one','two','three','four','six'];
public function team(){
return $this->belongsTo(Team::class,'team_id');
}
public function matchh(){
return $this->belongsTo(Matchh::class,'match_id');
}
public function player(){
return $this->belongsTo(Player::class,'player_id');
}
public function scoreupdate(){
return $this->belongsTo(Scoreupdate::class,'scoreupdate_id');
}
}
And This to my ScoreController.php
public function index()
{
$data=Score::all();
$team=Team::all();
$match=Matchh::all();
$player=Player::all();
$scoreupdate=Scoreupdate::all();
return view('admin.manage.score.index',compact('data','team','match','player','scoreupdate'));
}
public function store(Request $request)
{
Score::insert([
'match_id' => $request->match_id,
'team_id' => $request->team_id,
'player_id' => $request->player_id,
'scoreupdate_id' => $request->scoreupdate_id,
'outby_id' => $request->outby_id,
]);
$notification = array('message'=>'Scoreupdate Inserted!','alert-type'=>'success');
return redirect()->back()->with($notification);
}
And This is my index.blade.php
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0">Score</h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#teamModal">
+ Add New
</button>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">All score list here</h3>
</div>
<!-- /.card-header -->
{{-- card body --}}
<div class="card-body">
<table id="example1" class="table table-bordered table-striped table-sm">
<thead>
<tr>
<th>SL</th>
<th>Match Name</th>
<th>Team Name</th>
<th>Player Name</th>
<th>Out type</th>
<th>Out by type</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($data as $key => $row)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $row->matchh->match_name }}</td>
<td>{{ $row->team->team_name }}</td>
<td>{{ $row->player->player_name }}</td>
<td>{{ $row->scoreupdate->out_type }}</td>
<td>{{ $row->scoreupdate->out_by_type }}</td>
<td>
<a href="#" class="btn btn-info btn-sm edit"
data-id="{{ $row->id }}" data-toggle="modal"
data-target="#editModal"><i class="fas fa-edit"></i></a>
<a href="{{ route('score.delete', $row->id) }}"
class="btn btn-danger btn-sm" id="delete"><i
class="fas fa-trash"></a>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
</div>
</div>
</div>
</section>
</div>
{{-- insert modal --}}
<!-- Modal -->
<div class="modal fade" id="teamModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Player Modal</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="{{ route('score.store') }}" method="Post">
#csrf
<div class="modal-body">
<div class="from-group">
<label for="player_name">Match Name</label>
<select class="form-control" name="match_id" required="">
#foreach ($match as $row)
<option value="{{ $row->id }}">{{ $row->match_name }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="player_name">Team Name</label>
<select class="form-control" name="team_id" required="">
#foreach ($team as $row)
<option value="{{ $row->id }}">{{ $row->team_name }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="player_name">Player Name</label>
<select class="form-control" name="player_id" required="">
#foreach ($player as $row)
<option value="{{ $row->id }}">{{ $row->player_name }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="out type">Out type</label>
<select class="form-control" name="scoreupdate_id" required="">
#foreach ($scoreupdate as $row)
<option value="{{ $row->id }}">{{ $row->out_type }}</option>
#endforeach
</select>
</div>
<div class="from-group">
<label for="out by type">Out by type</label>
<select class="form-control" name="outby_id" required="">
#foreach ($scoreupdate as $row)
<option value="{{ $row->id }}">{{ $row->out_by_type }}</option>
#endforeach
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="Submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
The problem is that when I add not out in my out type box which is id(1) in scoreupdates table and add caught in my out by type box which is id(2) of my scoreupdates table
It's inserting and retrieving not out and (-) where both of them hold id(1) of scoreupdates table but I want that when I insert not out it will insert and retrieve not out and when add caught it will insert and retrieve caught.
scores table database
I think this could be wrong you are doing
<td>{{ $row->scoreupdate->out_type }}</td
<td>{{ $row->scoreupdate->out_by_type }}</td>
On both column, you are trying to retrieve data from scoreUpdate, but looking at your database it looks like they are two foreign columns and it should be some other relation from relation outby_id, not scoreupdate_id.
On model, its showing,
public function scoreupdate(){
return $this->belongsTo(Scoreupdate::class,'scoreupdate_id');
}
It's retriving data from scoreupdate_id not outby_id

can't refresh a page after updateing a form in laravel

hello i need to do an update inside a model using Laravel, the problem is when i click on the update button (his name in the code is Modifier) the page is not refreshing.
i have tried to work with an a tag in place of button .and with the a tag the page refresh but my data is not updating.
can someone tell me where is the problem in the code
the index view code :
<table class="table table-bordered table-left">
<thead>
<tr>
<th>#</th>
<th>Nom</th>
<th>Email</th>
<th>Rôle</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($users as $key=>$user)
<tr>
<td>{{ $key+1 }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>
#if ($user->is_admin==1)Administrateur
#else Caissier
#endif
</td>
<td>
<div class="btn-group">
<a class="btn btn-success" href="" data-toggle="modal" data-target="#edituser{{ $user->id }}">
<i class="fas fa-edit"></i>
</a>
<a href="" class="btn btn-danger">
<i class="fas fa-trash"></i>
</a>
</div>
</td>
</tr>
{{-- edit model --}}
<div class="modal right fade" id="edituser{{ $user->id }}" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="staticBackdropLabel">Modifier l'utilisateur</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{ route('users.update', $user->id) }}" method="post">
#csrf
#method('put')
<div class="form-group">
<label for="name">Nom</label>
<input type="text" value="{{ $user->name }}" name="name" class="form-control">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" value="{{ $user->email }}" name="email" class="form-control">
</div>
<div class="form-group">
<label for="name">Mot de passe</label>
<input type="password" readonly name="password" value="{{ $user->password }}" class="form-control">
</div>
{{-- <div class="form-group">
<label for="name">Confirmer le mot de passe</label>
<input type="password" name="confirm_password" class="form-control">
</div> --}}
<div class="form-group">
<label for="name">Rôle</label>
<select name="is_admin" id="" class="form-control">
<option value="1" #if ($user->is_admin==1)
selected
#endif>Administrateur</option>
<option value="2" #if ($user->is_admin==2)
selected
#endif>Caissier</option>
</select>
</div>
<div >
<button class="btn btn-success btn-block">Modifier</button>
</div>
</form>
</div>
</div>
</div>
</div>
#endforeach
</tbody>
</table>
the controller code :
public function update(Request $request, $id)
{
$users = User::find($id);
if (!$users) {
return back()->with('Error','user created');
}
$users->update($request->all());
return back()->with('Success','user created');
}
Your button
<button class="btn btn-success btn-block">Modifier</button>,
should be
<button class="btn btn-success btn-block" type="submit">Modifier</button> in order to submit the form to your controller.

Failed to load excel\laravel-excel

I want to export only filtered data in view blade. I am using Laravel 7 and maatwebsite/excel 3.1 and PHP 7.4.2.
I went through the documentation and applied this:
View
<a href="{!! route('users.export-filter') !!}" class="btn btn-success">
<i class="la la-download"></i>
Export Filter
</a>
web.php
Route::get('/users/export-filter', 'Admin\UserController#filter')->name('users.export-filter');
UserController.php
public function filter()
{
return Excel::download(new FilterUserExport, 'filter.xlsx');
}
FilterUserExport.php
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use Modules\User\Entities\User;
use Illuminate\Contracts\View\View;
class FilterUserExport implements FromView, ShouldAutoSize, WithEvents
{
/**
* #return View
*/
public function view(): View
{
$users = app(User::class)->newQuery();
if ( request()->has('search') && !empty(request()->get('search')) ) {
$search = request()->query('search');
$users->where(function ($query) use($search) {
$query->where('first_name', 'LIKE', "%{$search}%")
->orWhere('last_name', 'LIKE', "%{$search}%")
->orWhere('email', 'LIKE', "%{$search}%")
->orWhere('mobile', 'LIKE', "%{$search}%");
});
}
return view('users.index', compact('users'));
}
/**
* #return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->getDelegate()->setRightToLeft(true);
},
];
}
}
index.blade.php
#extends("admin-panel.layouts.master")
#section("content")
<div class="content-body">
<section class="grid-with-inline-row-label" id="grid-with-inline-row-label">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">
<a data-action="collapse">
<i class="ft-plus mr-1"></i>
ثبت فیلتر
</a>
</h4>
<a class="heading-elements-toggle"><i class="ft-align-justify font-medium-3"></i></a>
<div class="heading-elements">
<ul class="list-inline mb-0">
<li><a data-action="collapse"><i class="ft-plus"></i></a></li>
<li><a data-action="reload"><i class="ft-rotate-cw"></i></a></li>
<li><a data-action="expand"><i class="ft-maximize"></i></a></li>
<li><a data-action="close"><i class="ft-x"></i></a></li>
</ul>
</div>
</div>
<div class="card-content collapse #if( $errors->any() ) show #endif">
<div class="card-body">
<form action="{!! route('admin::users.index') !!}" method="get">
<div class="form-body">
<div class="row">
<div class="col-6 form-group">
<label for="search">جستجو</label>
<input type="text" name="search" id="search" class="form-control"
placeholder="جستجو..."
aria-label="جستجو" value="{{ request()->query('search') }}">
</div>
<div class="col-6 form-group">
<label for="user_type">گروه کاربری</label>
<select id="user_type" name="user_type" class="form-control">
<option value="" {{ (request()->query('user_type') == '')? "selected" : "" }}>-</option>
<option value="is_special" {{ (request()->query('user_type') == 'is_special')? "selected" : "" }}>کاربر ویژه</option>
<option value="is_user" {{ (request()->query('user_type') == 'is_user')? "selected" : "" }}>کاربر عادی</option>
<option value="is_admin" {{ (request()->query('user_type') == 'is_admin')? "selected" : "" }}>مدیریت سیستم</option>
</select>
</div>
<div class="col-6 form-group">
<label for="target">فیلتر کاربران</label>
<select id="target" name="target" class="form-control">
<option value="" {{ (request()->query('target') == '')? "selected" : "" }}>-</option>
<option value="active" {{ (request()->query('target') == 'active')? "selected" : "" }}>کاربر ویژه</option>
<option value="orderedAtLeastOnce" {{ (request()->query('target') == 'orderedAtLeastOnce')? "selected" : "" }}>کاربر عادی</option>
<option value="orderedInLastMonth" {{ (request()->query('target') == 'orderedInLastMonth')? "selected" : "" }}>مدیریت سیستم</option>
<option value="neverOrdered" {{ (request()->query('target') == 'neverOrdered')? "selected" : "" }}>مدیریت سیستم</option>
</select>
</div>
<div class="col-md-6 form-group">
<label for="categoryId">دسته بندی</label>
{!! Form::select('categoryId', \Modules\Category\Entities\Category::whereNull('parentId')->get()->pluck('title', 'id')->toArray(), null, [
'class' => 'form-control',
'id' => 'categoryId',
'placeholder' => 'انتخاب دسته بندی',
]) !!}
</div>
</div>
<div class="d-flex justify-content-between form-actions pb-0">
<div>
<button type="submit" class="btn btn-primary">ارسال <i class="ft-send position-right"></i>
</button>
<button type="reset" class="btn btn-warning">ریست <i class="ft-refresh-cw position-right"></i>
</button>
</div>
<div>
<a href="{!! route('admin::users.export-excel') !!}" class="btn btn-success">
<i class="la la-download"></i>
صادر
</a>
<a href="{!! route('admin::users.export-filter') !!}" class="btn btn-success">
<i class="la la-download"></i>
Export Filter
</a>
<a href="{!! route('admin::users.export-special-excel') !!}" class="btn btn-success">
<i class="la la-download"></i>
صدور کاربران ویژه
</a>
<a href="{!! route('admin::users.import-excel') !!}" class="btn btn-primary">
<i class="la la-cloud-download"></i>
آپلود
</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div id="recent-transactions" class="col-xl-12 col-12">
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-md">
<div class="row justify-content-between align-items-center mr-md-1 mb-1">
<div class="col-sm">
<h4 class="card-title mb-2 mb-sm-0">فهرست کاربران</h4>
</div>
</div>
</div>
<div class="col-auto">
<a href="{!! route('admin::users.create') !!}" class="btn btn-info">
<i class="la la-plus"></i>
ایجاد کاربر جدید
</a>
</div>
</div>
</div>
<div class="card-content">
#if( $users->count() > 0 )
#includeWhen( Module::find('notification') && request()->has('search'), 'user::admin.users._notification' )
<div class="table-responsive">
<table id="recent-orders" class="table table-hover table-xl mb-0">
<thead>
<tr>
<th class="border-top-0"># شناسه</th>
<th class="border-top-0">نام و نام خانوادگی</th>
<th class="border-top-0">موبایل</th>
{{-- <th class="border-top-0">ایمیل</th>--}}
<th class="border-top-0">کد ملی</th>
<th class="border-top-0">مدیر</th>
<th class="border-top-0">وضعیت</th>
<th class="border-top-0">ویژه</th>
<th class="border-top-0">آخرین ورود</th>
<th class="border-top-0">عملیات</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<td class="text-truncate">
<i class="la la-dot-circle-o success font-medium-1 mr-1"></i>
{{ $user->id }}
</td>
<td class="text-wrap">
{{ $user->first_name.' '.$user->last_name }}
</td>
<td class="text-wrap">
{{ $user->mobile }}
</td>
{{--<td class="text-wrap">
{{ $user->email }}
</td>--}}
<td class="text-wrap">
{{ $user->national_id }}
</td>
<td class="text-wrap">
#if( $user->is_admin )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( !$user->disabled_at )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( $user->is_special_user == 1 )
<i class="ft-check-circle text-success"></i>
#else
<i class="ft-x-circle text-danger"></i>
#endif
</td>
<td class="text-wrap">
#if( $user->last_login_at )
{{ getShamsiDate($user->last_login_at) }}
#else
—
#endif
</td>
<td>
<div class="row flex-nowrap">
<a href="{{ route('admin::users.show', $user) }}" class="mr-1">
<i class="ft-eye text-grey text-shadow-custom font-medium-5 font-weight-normal"></i>
</a>
<a href="{{ route('admin::users.edit', $user) }}" class="mr-1">
<i class="ft-edit text-grey text-shadow-custom font-medium-4 font-weight-normal"></i>
</a>
<form action="{{ route('admin::users.destroy', $user) }}"
method="post"
#submit.prevent="confirmDelete">
#method('delete')
#csrf
<button type="submit" class="btn btn-default p-0">
<i class="ft-trash-2 text-grey font-medium-5 font-weight-normal"></i>
</button>
</form>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="pagination-flat">
{{ $users->links() }}
</div>
</div>
#else
<div class="text-center my-2">
<p>نتیجه‌ای برای نمایش وجود ندارد.</p>
</div>
#endif
</div>
</div>
</div>
</div>
</section>
</div>
#endsection
I get this error
The export submit button is sending everything to Excel. How do I make it to send only the filtered data. Thanks
You need to get rid of the other HTML in your view such as forms, inputs, and buttons. Keep the view only to a minimum of the table that needed for your Excel.

Getting validation to work for address in laravel

I'm making a page that before the user submits they need to add their address.
For example: The user goes to the order confirmation and they forget to add their address and they fill in the rest of the page (the page has delivery/collection radio buttons and payment option radio buttons) when the user clicks on the confirm button the page needs to go back and give an error that the address wasn't entered.
The address portion of the page only has a "Add Address" button that takes the user to a form to enter their address.
Is there a way to do this. I thought maybe validation would work but I don't think I'm doing it correctly in this instance.
I have a hidden form that grabs some info and it has an address field in it so that it gets passed into the controller so that I can save it, but it's like it doesn't pick it up
My order-confirmation.blade.php
#extends('layouts.public')
#section('content')
<div class="content_wrapper">
<h1>Order Confirmation</h1>
<?php
$delivery = getDeliveryFee();
?>
{{ $invoice_number }}
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12 mt-15">
#if($message = Session::get('success'))
<div class="alert alert-success" role="alert">
{{ $message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#endif
#if($message = Session::get('error'))
<div class="alert alert-danger" role="alert">
{{ $message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#endif
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Billing Information
</button>
</h2>
</div>
<div id="collapseOne" class="collapse {{ !$errors->any() ? 'show' : '' }}" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
<div class="row">
<div class="col-lg-6">
<div class="address">
#if ($errors->confirmation_errors->has('delivery_address'))
<div class="help-block text-danger">
<strong>Please add an address NOW</strong>
</div>
#endif
#foreach($addresses as $address)
#if(!empty($address->complex))
{{ $address->complex }},
#endif
<div>{{ $address->address }},</div>
<div>{{ $address->suburb }},</div>
<div>{{ $address->city }},</div>
<div>{{ $address->province }},</div>
<div>{{ $address->postal_code }}</div>
<div class="row edit-delete">
<div class="col-lg-2">
<a class="btn btn-primary edit-button" href="{{ route('account.edit.delivery.address', [$address->id]) }}">Edit</a>
<span>/</span>
</div>
<div class="col-lg-2">
<form action="{{ route('account.delete.delivery.address', [$address->id]) }}" method="post">
#csrf
{{ method_field('DELETE') }}
<button class="btn btn-danger delete-button"><i class="fa fa-pencil"></i> Delete</button>
</form>
</div>
</div>
#endforeach
</div>
</div>
<div class="col-lg-6">
Add Address
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h2 class="mb-0">
<button class="btn btn-link collapsed" id="delivery-collection" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Delivery/Collection
</button>
</h2>
</div>
<div id="collapseTwo" class="collapse {{ $errors->confirmation_errors->any() ? 'show' : '' }}" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
<p>
Please select your delivery option
</p>
#if ($errors->confirmation_errors->has('delivery_collection'))
<div class="help-block text-danger">
<strong>Please select your delivery option</strong>
</div>
#endif
<div class="delivery-option">
<input type="radio" class="form-check-input {{ $errors->confirmation_errors->has('delivery_collection') ? 'is-invalid' : '' }}" name="delivery-option" id="delivery" value="delivery">
<label for="delivery" class="form-check-label">
Delivery
</label>
<input type="radio" class="form-check-input {{ $errors->confirmation_errors->has('delivery_collection') ? 'is-invalid' : '' }}" name="delivery-option" id="collection" value="collection">
<label for="collection" class="form-check-label">
Collection
</label>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h2 class="mb-0">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Payment Options
</button>
</h2>
</div>
<div id="collapseThree" class="collapse {{ $errors->any() ? 'show' : '' }}" aria-labelledby="headingThree" data-parent="#accordionExample">
<div class="card-body">
#if ($errors->has('payment_option'))
<div class="help-block text-danger">
<strong>Please select a payment option</strong>
</div>
#endif
<div class="row">
<div class="col-lg-12">
<div class="payment-option">
<input type="radio" class="form-check-input {{ $errors->has('payment_method') ? 'is-invalid' : '' }}" name="payment_method" id="payfast-eft" value="payfast-eft">
<label for="payfast-eft" class="form-check-label">
EFT with PayFast
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h2 class="mb-0">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseFour" aria-expanded="false" aria-controls="collapseThree">
Review Your Order
</button>
</h2>
</div>
<div id="collapseFour" class="collapse" aria-labelledby="collapseFour" data-parent="#accordionExample">
<div class="card-body">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Product</th>
<th scope="col">Code</th>
<th scope="col">Quantity</th>
<th scope="col">Unit Price</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
#foreach($products as $product)
<?php
$image = getImagesArray($product['item']['image']);
?>
<tr>
<th>
#if(!empty($image))
<img src={!! asset("product_images/thumbs/$image[0]") !!}>
#endif
{{ $product['item']['title'] }}
</th>
<td>{{ $product['item']['supplier_code'] }}</td>
<td>{{ $product['qty'] }}</td>
<td>R {{ $product['item']['price'] }}</td>
<td>R {{ $product['price'] }}</td>
</tr>
#endforeach
<tr>
<th colspan="4">
<div class="float-right">
Sub Total
</div>
</th>
<td id="totalPrice" data-price="{{ $totalPrice }}">
R {{ $totalPrice }}
</td>
</tr>
<tr class="delivery-fees">
<th colspan="4">
<div class="float-right">
Delivery Fee
</div>
</th>
<td id="delivery-price" data-price="{{ $delivery }}">
R {{ $delivery }}
</td>
</tr>
<?php
$total = $totalPrice + $delivery;
?>
<tr class="total-price">
<th colspan="4">
<div class="float-right">
Total:
</div>
</th>
<td>
R <span id="completePrice"></span>
</td>
</tr>
</tbody>
</table>
<div class="confirm-order-btn pb-15">
#foreach($products as $product)
<!-- BEGIN PAYFAST EFT -->
<div class="payfast-eft" style="display: none">
<form action="{{ route('payment.gateway') }}" method="POST">
#csrf
<input type="hidden" name="merchant_id" value="merchant_id">
<input type="hidden" name="merchant_key" value="merchant_key">
<input type="hidden" name="return_url" value="{{ route('payfast.success') }}">
<input type="hidden" name="cancel_url" value="{{ route('payfast.cancel') }}">
<input type="hidden" name="m_payment_id" value="{{ $invoice_number }}">
<input type="hidden" name="amount" class="completePrice" value="">
<input type="hidden" name="item_name" value="{{ $product['item']['title'] }}">
<input type="hidden" name="item_description" value="{{ $product['item']['description'] }}">
<input type="hidden" name="email_confirmation" value="1">
<input type="hidden" name="confirmation_address" value="">
<input type="hidden" name="payment_method" value="payfast_eft">
<input type="hidden" name="delivery_collection" class="delivery_collection" value="">
<input type="hidden" name="delivery_fee" class="delivery_fee" value="{{ $delivery }}">
<!-- THIS IS WHERE THE ADDRESS IS ADDED TO THE HIDDEN FORM -->
<input type="hidden" name="delivery_address" class="delivery_address" value="{{ $address }}">
<?php
$success = url('payfast-success');
$cancel = url('payfast-cancel');
$notify = url('payfast-notify');
$original_str = getAscii('merchant_id=merchant_id&merchant_key=merchant_key&return_url='.$success.'&cancel_url='.$cancel.'&notify_url='.$notify.'&m_payment_id=01AB&amount='.$totalPrice.'&item_name=Test Item&item_description=A test product&email_confirmation=1&confirmation_address=email#domain.com&payment_method=eft');
$hash_str = hash('MD5', $original_str);
$hash = strtolower($hash_str);
?>
<input type="hidden" name="signature" value="{{ $hash }}">
<button type="submit" class="btn btn-success float-right confirm-payfast-order">
Confirm Order
</button>
</form>
</div>
<!-- END PAYFAST EFT -->
#endforeach
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
var price = $("#totalPrice").data('price'); //get data-price by this syntax
$('#completePrice').html(price);
$('.completePrice').val(price);
$('input[type="radio"]').click(function(){
if($(this).attr("value")=="collection"){
$(".delivery-fees").hide('slow');
var price = $("#totalPrice").data('price'); //get data-price by this syntax
var deliveryprice = 0; //get data-price by this syntax
var totalPrice = parseFloat(price) + parseFloat(deliveryprice);
$('#completePrice').html(totalPrice);
$('.completePrice').val(totalPrice);
$('.delivery_collection').val('collection');
$('.confirm-order').removeAttr('disabled');
$('.confirm-payfast-order').removeAttr('disabled');
}
if($(this).attr("value")=="delivery"){
$(".delivery-fees").show('slow');
var price = $("#totalPrice").data('price'); //get data-price by this syntax
var deliveryprice = $("#delivery-price").data('price'); //get data-price by this syntax
var totalPrice = parseFloat(price) + parseFloat(deliveryprice);
$('#completePrice').html(totalPrice);
$('.completePrice').val(totalPrice);
$('.delivery_collection').val('delivery');
}
});
/* BEGIN EFT PAYFAST */
$('input[type="radio"]').click(function(){
if($(this).attr("value")=="payfast-eft"){
$(".payfast-eft").show('slow');
$(".payfast-card").hide();
$(".i-pay").hide();
$(".confirm-order").hide();
$(".payfast-debit-card").hide();
}
});
/* END EFT PAYFAST */
});
</script>
#stop
my controller function
public function paymentGateway(Request $request)
{
if($request->payment_method == 'payfast_eft')
{
$process = 'Order Paid';
$paid = '1';
}
if($request->delivery_collection == 'collection')
{
$delivery_fee = null;
}else{
$delivery_fee = $request->delivery_fee;
}
$orders = Order::all();
$oldCart = Session::get('cart');
$cart = new Cart($oldCart);
$validation = Validator::make($request->all(), $this->getRules());
if($validation->fails())
{
return redirect()->route('cart.deliveryConfirmation')
->withErrors($validation, 'confirmation_errors')
->with('error', 'There were validation errors');
}
foreach($orders as $order)
{
$order = Order::find($order->id)->where('invoice_number', $request->m_payment_id)->first();
$order->cart = serialize($cart);
$order->address = $request->delivery_address;
$order->delivered_date = null;
$order->delivery_fee = $delivery_fee;
$order->delivery_option = $request->delivery_collection;
$order->process = $process;
$order->order_date = Carbon::now('+2:00');
$order->payment_method = $request->payment_method;
$order->paid = $paid;
$order->order_price = $request->amount;
$order->save();
}
$merchant_id = $request->merchant_id;
$merchant_key = $request->merchant_key;
$return_url = $request->return_url;
$cancel_url = $request->cancel_url;
$m_payment_id = $request->m_payment_id;
$amount = $request->amount;
$item_name = $request->item_name;
$item_description = $request->item_description;
$email_confirmation = '1';
$confirmation_address = 'email#domain.com';
$payment_method = $request->payment_method;
$signature = $request->signature;
if($request->payment_method == 'payfast_eft')
{
$url = 'https://sandbox.payfast.co.za/eng/process?merchant_id='.$merchant_id.'&merchant_key='.$merchant_key.'&return_url='.$return_url.'&cancel_url='.$cancel_url.'&m_payment_id='.$m_payment_id.'&amount='.$amount.'&item_name='.$item_name.'&item_description='.$item_description.'&email_confirmation='.$email_confirmation.'&confirmation_address='.$confirmation_address.'&payment_method='.$payment_method;
}
return redirect()->to($url);
}
protected function getRules()
{
return [
'delivery_collection' => 'required',
'payment_method' => 'required',
'delivery_address' => 'required'
];
}
basically on the paymentGateway controller you need to check whether the address is provided if not redirect to the previous page where address is selected and saved in db

When I click on edit button give me error

When I click in edit button it gives me a error, what is problem I can not understand now, please help me
Trying to get property 'id' of non-object (View: C:\xampp\htdocs\ytl\resources\views\profile\edit.blade.php)
This is my userprofilecontroller
public function edit( Request $request, $id){
$user_profile_id = UserProfile::where('id', '=', $id)->firstOrFail();
$exchanges = Exchange::pluck('exchange','id')->all();
$markets = Market::pluck('market','id')->all();
$countries = Country::pluck('country','id')->all();
$brokerage_company = BrokerageCompany::pluck ('brokerage_company','id')->all();
$user_profile = UserProfile::pluck('charge_intraday','charge_delivery','charge_per_lot','charge_per_order')->all();
return view('profile.edit', compact('user_profile_id','exchanges','markets','countries','brokerage_company','user_profile'));
}
public function update(Request $request, $id){
$user_profile_id = UserProfile::findOrFail($id);
$input = $request->except( 'brokerage_company','user_profile');
$user_id = $user_profile->update($input);
return redirect('/profile');
}
This is profile\index.blade.php file
<div class="card card-table">
<div class="card-header">Basic Tables
<div class="tools dropdown"><span class="icon mdi mdi-download"></span><a class="dropdown-toggle" href="#" role="button" data-toggle="dropdown"><span class="icon mdi mdi-more-vert"></span></a>
<div class="dropdown-menu" role="menu"><a class="dropdown-item" href="#">Action</a><a class="dropdown-item" href="#">Another action</a><a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div><a class="dropdown-item" href="#">Separated link</a>
</div>
</div>
</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th style="width:10%;">Country</th>
<th style="width:10%;">Exchange</th>
<th class="number">Market</th>
<th class="number">Company</th>
<th class="actions">Charges</th>
</tr>
</thead>
#if($user_profile)
<tbody>
#foreach($user_profile as $user_profiles)
<tr>
<td>{{$user_profiles->country->country}}</td>
<td>{{$user_profiles->exchange->exchange}}</td>
<td>{{$user_profiles->market->market}}</td>
<td>{{$user_profiles->brokerage_company->brokerage_company}}</td>
<td class="cell-detail"><span>Intaday-charge</span>{{$user_profiles->charge_intraday}}
<span class="cell-detail-description">Delivery-charge</span>
{{$user_profiles->charge_delivery}}</td>
{{--<td>{{$user_profiles->charge_per_lot}}</td>--}}
{{--<td>{{$user_profiles->charge__per_order}} </td>--}}
<td> <a class="btn btn-info btn-sm" href="{{route('profile.edit', $user_profiles->id)}}">Edit</a></td>
</tr>
#endforeach
</tbody>
#endif
</table>
</div>
</div>
This is profile\edit.blade.php file
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Charge</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{--<form method="PATCH", id="form", action="{{action('Profile\UserProfileController#update',$user_profile_id->id)}} ", accept-charset="UTF-8">--}}
{{--{{ csrf_field() }}--}}
{{--{{ method_field('PATCH') }}--}}
{!! Form::model($user_profile,['method'=>'PATCH', 'action'=> ['Profile\UserProfileController#update',$user_profile->id]]) !!}
<div class="row">
<div class="col-md-6 mb-3 form-group">
Country:<select name="country_id" id="country" class="form-control " onchange="myfunc()" >
<option value="">Select</option>
#foreach($countries as $key=>$val )
<option value="{{ $val->id }}">{{ $val->country }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Exchange:<select name="exchange_id" id="exchange" class="form-control notselect" onchange="myfunc1()">
<option value="">Select</option>
{{--#foreach($exchanges as $key=>$val )--}}
{{--<option value="{{ $val->id }}">{{ $val->exchange }}</option>--}}
{{--#endforeach--}}
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Market<select name="market_id" id="market" class="form-control bindselect" >
<option value="">Select</option>
{{--#foreach($markets as $key=>$val )--}}
{{--<option value="{{ $val->id }}">{{ $val->market }}</option>--}}
{{--#endforeach--}}
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Company:<select name="brokerage_company_id" id="brokerage_company_id" class="form-control " >
<option value="">Select</option>
#foreach($brokerage_company as $key=>$val)
<option value="{{ $val->id }}">{{ $val->brokerage_company }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Intraday_charge: <input type="text" name="charge_intraday" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_delivery" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_per_lot" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_per_order" class="form-control"><br>
</div>
{!! Form::close() !!}
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" value="Submit" name="form1" class="btn btn-primary">Save changes</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
It seems like you misunderstood the Pluck method. Pluck is to take several properties out an array by their key. Nothing to do with selecting columns from a Database.
I guess you want to select a single UserProfile. And the right way of doing this is as follows:
public function edit(Request $request, $id){
$user_profile = UserProfile::findOrFail($id); // Select a UserProfile by ID or fail
$exchanges = Exchange::all('exchange', 'id');
$markets = Market::all('market','id');
$countries = Country::all('country','id');
$brokerage_company = BrokerageCompany::all ('brokerage_company','id');
// I dont know what you want with this statement?
// $user_profile = UserProfile::pluck('charge_intraday','charge_delivery','charge_per_lot','charge_per_order')->all();
return view('profile.edit', compact('user_profile','exchanges','markets','countries','brokerage_company'));
}

Resources