I hope you are well ? I have a feature to integrate that should allow users to boost articles based on a certain number of keywords. The principle is that the user selects one or more articles and with each selected article, he associates keywords which are also made via selections. My concern is that I can't combine the chosen keywords with each selected article. I use Laravel and Livewire.
my selection of articles and keywords
In my livewire component
public $allData;
public $selectedProducts = [];
public $selectedWords = [];
public $selectAll = false;
public bool $bulkDisabled = false;
public $selectedProductIndex = null;
public function updatedSelectedProducts($productIndex)
{
$this->selectedProductIndex = $productIndex;
if ($this->selectedProducts) {
$this->bulkDisabled = true;
} else {
$this->bulkDisabled = false;
}
if (count($this->selectedProducts) >= $this->pack->nombre_article) {
$this->limiteAtteint = true;
} else {
$this->limiteAtteint = false;
}
}
public function updatedSelectedWords($value)
{
$this->allData =
[
(object) array('key' =>[ $this->selectedProductIndex], 'key2' => $value),
];
}
When I dump
dd
But I would like to have something like this as in the picture
array:2 [▼
0 => array:2 [▼
"key" => array:1 [▼
0 => array:2 [▼
0 => "product 1"
]
]
"key2" => array:1 [▼
0 => "shoes",
1 => "clothes"
]
],
1 => array:2 [▼
"key" => array:1 [▼
0 => array:2 [▼
0 => "product 2"
]
]
"key2" => array:1 [▼
0 => "shoes"
]
]
]
My livewire component blade file
<table class="table table-bordered table-striped table-hover dataTable js-exportable">
<thead>
<tr>
<th></th>
<th>Keywords</th>
<th>Product name</th>
<th>Category</th>
<th>Price</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th>Keywords</th>
<th>Product name</th>
<th>Category</th>
<th>Price</th>
</tr>
</tfoot>
<tbody>
#foreach ($articles as $article)
<tr>
<td>
<input wire:ignore type="checkbox" class="filled-in chk-col-red" value="{{$article->id}}" wire:model="selectedProducts"
/>
<label for="md_checkbox_21{{$article->id}}"></label>
</td>
<td>
<section style="position: absolute" wire:ignore>
<div class="row d-flex justify-content-center mt-0">
<div class="col-md-12">
<select id="choices-multiple-remove-button" name="selectedWords{{$article->id}}" wire:model="selectedWords" class="selectpicker" multiple aria-label="Default select example" data-live-search="true" placeholder="Select up to 3 tags" multiple>
{{-- $mots for workeys --}}
#foreach ($mots as $mot)
<option value="{{$mot->intitule}}">{{$mot->intitule}}</option>
#endforeach
</select>
</div>
</div>
</section>
</td>
<td> <a class="black-text" href="{{ route('articles.show', $article) }}">
{{ ucFirst($article->intitule) }} </a></td>
<td> <a class="black-text" href="{{ route('articles.show', $article) }}">
#if ($article->categories)
#foreach ($article->categories as $categorItem)
{{ $categorItem->categorie->intituleCategorie }}
#endforeach
#endif
</a></td>
<td> <a class="black-text"
href="{{ route('articles.show', $article) }}">{{ formatMontant($article->prix) }}
</a></td>
</tr>
#endforeach
</tbody>
</table>
Related
I have the following method defined in my controller. I want to pass the value of $title along with the search results so that it can be displayed at the top of the blade page, but I am unsure how to do it.
public function index_sog(Request $request)
{
$title = 'Standard Operating Guideline';
return view('knowledgebase.index', [
'kbase' => Knowledgebase::orderBy('category', 'asc')
->filter(request(['tags', 'search']))
->where('type','SOG')
->paginate(20),
'search' => $request->input('search')
]);
}
My output...
<h4>{{//TITLE SHOULD GO HERE//}}</h4>
<div class="panel-container show">
<div class="panel-content">
#foreach ($kbase->groupBy('category') as $category => $group)
<table class="table">
<tr>
<th colspan="3" class="text-center bg-fusion-50"><strong>{{ $category }} <strong></th>
</tr>
#foreach ($group as $kb)
<tr>
<td>{{ $kb->title }}</td>
<td></td>
<td></td>
</tr>
#endforeach
</table>
#endforeach
</div>
</div>
ADD on return variables. And you can use on blade like {{ $title }}
> return view('knowledgebase.index', [
> 'kbase' => Knowledgebase::orderBy('category', 'asc')
> ->filter(request(['tags', 'search']))
> ->where('type','SOG')
> ->paginate(20),
> 'search' => $request->input('search'),
> 'title' => $title
> ]);
For example you can do this way:
return view('knowledgebase.index', [
'kbase' => Knowledgebase::orderBy('category', 'asc')
->filter(request(['tags', 'search']))
->where('type','SOG')
->paginate(20),
'search' => $request->input('search')
])->with('title', $title);
By adding the ->with() method to the return.
You can also put it inside the array of variables that you already have in return.
And then in your view:
<h4>{{ $title }}</h4>
Hi I just started working in laravel 8 and I would like to know how to fetch data in database and print data
I have a template of a table with a search bar to see and find user in our database
Here is our controller for the table
DashboardController
<?php
namespace App\Http\Controllers;
use Auth;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function dashboard()
{
$dashboardTitle = "Dashboard";
$isCurrent = "dashboard";
return view('dashboard.index', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
public function profile()
{
$dashboardTitle = "Profile";
$isCurrent = "Profile";
return view('dashboard.profile', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
public function directory()
{
$dashboardTitle = "Directory";
$isCurrent = "Directory";
return view('dashboard.directory', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
public function journal()
{
$dashboardTitle = "Journal";
$isCurrent = "Journal";
return view('dashboard.journal', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
public function files()
{
$dashboardTitle = "Files";
$isCurrent = "Files";
return view('dashboard.files', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
}
Here is the view
directory
#extends('dashboard.layouts.dashboard-layout')
#push('css')
<!-- Custom styles for this page -->
<link href="{{asset('dashboards/vendor/datatables/dataTables.bootstrap4.min.css')}}" rel="stylesheet">
#endpush
#section('content')
<!-- Page Heading -->
<h1 class="h3 mb-2 text-gray-800">Tables</h1>
<p class="mb-4">DataTables is a third party plugin that is used to generate the demo table below.
For more information about DataTables, please visit the <a target="_blank"
href="https://datatables.net">official DataTables documentation</a>.</p>
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">DataTables Example</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<td></td>
<td></td>
<td></td>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
</div>
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
#endsection
#push('script')
<!-- Page level plugins -->
<script src="{{asset('dashboards/vendor/datatables/jquery.dataTables.min.js')}}"></script>
<script src="{{asset('dashboards/vendor/datatables/dataTables.bootstrap4.min.js')}}"></script>
<!-- Page level custom scripts -->
<script src="{{asset('dashboards/js/demo/datatables-demo.js')}}"></script>
#endpush
Our table name is users and I want to print it in the table using a loop
Database
Add new rows in database if you haven't (position, office ...)
Controler
...
$users = User::all();
return view('dashboard.directory', [
'users' => $users
]
...
Blade
#foreach($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->postion }}</td>
<td>{{ $user->office }}</td>
<td>{{ $user->age }}</td>
<td>{{ $user->start_date }}</td>
<td>{{ $user->salary }}</td>
</tr>
#endforeach
To retrieve all users in your db, you have to :
Dashboard Controller
public function directory(){
$dashboardTitle = "Directory";
$isCurrent = "Directory";
$users = User::all();
return view('dashboard.directory', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent,
'users' => $users
]);
}
In Blade
#foreach($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->postion }}</td>
<td>{{ $user->office }}</td>
<td>{{ $user->age }}</td>
<td>{{ $user->start_date }}</td>
<td>{{ $user->salary }}</td>
</tr>
#endforeach
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 2 years ago.
i am beginner in laravel. I want to update a data but I get an error like this : Trying to get property 'id' of non-object'
This is my Controller :
public function hitung(Request $request)
{
$tanggal = date("Y-m-d");
$keuangan = array(
'bahan_baku' => $request->bahan_baku,
'biaya_tambahan' => $request->biaya_tambahan,
'jumlah_tempe' => $request->jumlah_tempe,
'biaya_produksi' => $request->bahan_baku + $request->biaya_tambahan,
'hasil_penjualan' => $request->jumlah_tempe * 1000,
'hasil_pendapatan' => ($request->jumlah_tempe * 1000) - ($request->bahan_baku + $request->biaya_tambahan),
'tanggal' => $tanggal,
);
Keuangan::create($keuangan);
return view('keuangan.hasil', compact('keuangan'));
}
public function edit($id)
{
$keuangan = Keuangan::find($id);
return view('/keuangan/edit', compact('keuangan'));
}
}
This is section from my view :
#extends('layouts.master')
#section('title','Manajemen Keuangan')
#section('content')
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<div class="form-group">
<h4>Keuangan :<strong style="color: red;"> {{ Carbon\Carbon::parse( $keuangan['tanggal'] )->translatedFormat("d F Y") }} </strong></h4>
</div>
<table class="table table-borderless">
<tbody>
<tr>
<td><strong>Biaya Produksi</strong></td>
<td>:    Rp. {{ number_format($keuangan['biaya_produksi']) }}</td>
</tr>
<tr>
<td><strong>Hasil Penjualan</strong></td>
<td>:    Rp. {{ number_format($keuangan['hasil_penjualan']) }}</td>
</tr>
<td><hr></td>
<td><hr align="left" style="width: 25%;"></td>
<tr>
<td><strong>Hasil Pendapatan</strong></td>
<td>:    Rp. {{ number_format($keuangan['hasil_pendapatan']) }}</td>
</tr>
</tbody>
</table>
#if($keuangan)
Edit
#endif
</div>
</div>
</div>
</div>
</div>
</div>
#stop
this is my route :
Route::get('/keuangan/edit/{id}', 'KeuanganController#edit');
this is section from my model :
class Keuangan extends Model
{
protected $table = 'keuangan';
protected $fillable = ['id', 'bahan_baku', 'biaya_tambahan', 'biaya_produksi', 'jumlah_tempe', 'hasil_penjualan', 'hasil_pendapatan'];
}
where is my fault ?? I just want to make an edit to the my data
try this return model instance not only array. becouse array don't have id
public function hitung(Request $request)
{
$tanggal = date("Y-m-d");
$keuangan = array(
'bahan_baku' => $request->bahan_baku,
'biaya_tambahan' => $request->biaya_tambahan,
'jumlah_tempe' => $request->jumlah_tempe,
'biaya_produksi' => $request->bahan_baku + $request->biaya_tambahan,
'hasil_penjualan' => $request->jumlah_tempe * 1000,
'hasil_pendapatan' => ($request->jumlah_tempe * 1000) - ($request->bahan_baku + $request->biaya_tambahan),
'tanggal' => $tanggal,
);
$keuangan = Keuangan::create($keuangan); // send this
return view('keuangan.hasil', compact('keuangan'));
}
So I have a table on blade view file, I have successfully exported it into the excel file. Now I want to export without exporting the 'Actions" column. How can I do that?
I have attached my code and blade file below, it works perfectly. I just want to export everything except the Actions Column as it contains Buttons for Database Operations
THIS IS MY EXPORT CLASS CODE:
public function view(): View
{
return view ('ims.view_inventory_history_table', [
'data' => inbound_history::all()
]);
}
public function headings(): array
{
return [
'ID',
'Warehouse',
'SKU',
'Child SKU',
'Units',
'Invoice No.',
'Container No.',
'Entry Date'
];}
/**
* #return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$cellRange = 'A1:W1'; // All headers
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);
},
];
}}
THIS IS MY CONTROLLER FUNCTION:
public function export_view()
{
return Excel::download(new inboundHistory(), 'inboundHistory.xlsx');
}
THIS IS MY ROUTE:
Route::Get('inbound_history/export_view' ,'imsController#export_view')->name('inbound_history.export_view');
THIS IS MY BLADE TABLE VIEW:
<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th style="width:5%">ID</th>
<th>Warehouse</th>
<th>SKU</th>
<th>Child SKU</th>
<th>Cases</th>
<th>Units</th>
<th>Invoice No.</th>
<th>Container No.</th>
<th>Entry Date</th>
<th class="disabled-sorting text-right" style="width:12%">Actions</th>
</tr>
</thead>
<tbody>
#foreach ($data as $row)
<tr>
<td>{{$row['id']}}</td>
<td>{{$row['warehouse']}}</td>
<td>{{$row['sku_parent']}}</td>
<td>{{$row['sku_child']}}</td>
<td>{{$row['total_cases']}}</td>
<td>{{$row['total_units']}}</td>
<td>{{$row['invoice_no']}}</td>
<td>{{$row['container_no']}}</td>
<td>{{$row['date_rec']}}</td>
<td class="td-actions text-right">
{{-- <a rel="tooltip" class="btn btn-success btn-link" href="{{action('imsController#edit',$row['id'])}}">
<i class="material-icons">edit</i></a> --}}
<a rel="tooltip" class="btn btn-danger btn-link" href="{{action('imsController#destroy',$row['id'])}}" onclick = "if (! confirm('Confirm: Press OK to delete the Entry.')) { return false; }"style="color: red;">
<i class="material-icons">close</i></a>
</td>
</tr>
#endforeach
</tbody>
I don't know if I got everything correctly, but why don't you do something like this:
Pass an additional variable to your blade template like $isView, when you want to create a view for the user.
And in your blade.php template you do something like this:
#isset($isView)
<th class="disabled-sorting text-right" style="width:12%">Actions</th>
#endisset
// do the same #isset test for the corresponding <td> element
When you want to render it to excel you just don't pass this variable and the column is not rendered.
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>