Route [news.shownewspublic] not defined - laravel-8

I want to view some data but I got this error Route [news.shownewspublic] not defined. (View: C:\xampp\htdocs\ContentBaseApp - 1.0.2\resources\views\news\indexnewspublic.blade.php)
This is my resources\views\news folder
This is resources\views\news\indexnewspublic.blade.php
#foreach ($news as $news)
<a class="btn btn-outline-info" href="{{route('news.shownewspublic'),$news->id}}">
<img src="/image/{{ $news->image }}" width="100px" class="col-2">
<div class="col-2" style="color: #1d2124">
<strong>App Name:- {{ $news->name }}</strong>
</div>
</a>
#endforeach
This is my NewsController.php
public function indexnewspublic()
{
$news = News::latest()->paginate(5);
return view('news.indexnewspublic',compact('news'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
public function shownewspublic(News $news)
{
return view('news.shownewspublic',compact('news'));
}
This is web.php
Route::resource('news', NewsController::class);
Route::get('/indexnewspublic', [NewsController::class, 'indexnewspublic']);
Route::get('/shownewspublic', [NewsController::class, 'shownewspublic']);

Solved by in indexnewspublic.php
#foreach ($news as $news) <a class="btn btn-outline-info" href="{{ url('shownewspublic/' . $news->id) }}"> {{ $news->name }} <img src="/image/{{ $news->image }}" width="100px" class="col-6"> </a> #endforeach
This is web.php
Route::get('indexnewspublic/{id}', [NewsController::class, 'indexnewspublic'])->name('indexnewspublic');
This is NewsController.php
public function indexnewspublic()
{
$news = News::latest()->paginate(5);
return view('news.indexnewspublic',compact('news'))
->with('i', (request()->input('page', 1) - 1) * 5);
}

Related

Add to cart button doesn't work. After click the button cart page doesn't load

This is Laravel 8.I set '/cart' route to href of add to cart button.but it also didn't work.got an error as 'session not found'.I made this while watching a youtube video.But it's not work.
What is the problem of my code?
Plz help me!
ShopComponent.php
<?php
namespace App\Http\Livewire;
use App\Models\Product;
use Livewire\Component;
use Livewire\WithPagination;
use Cart;
class ShopComponent extends Component
{
public function store($product_id,$product_name,$product_price){
Cart::add($product_id,$product_name,1,$product_price)->asseociate('App\Models\Product');
session()->flash('success_message','Item added in Cart');
return redirect()->route('product.cart');
}
public function render()
{
$products = Product::paginate(12);
return view('livewire.shop-component',['products'=>$products])->layout("layouts.base");
}
}
shop-component.blade.php
<div class="product-info">
<span>{{$product->name}}</span>
<div class="wrap-price"><span class="product-price">{{$product->regular_price}}</span></div>
Add To Cart
</div>
web.php
<?php
use App\Http\Livewire\HomeComponent;
use App\Http\Livewire\ShopComponent;
use App\Http\Livewire\CartComponent;
use App\Http\Livewire\CheckoutComponent;
use App\Http\Livewire\DetailsComponent;
use App\Http\Livewire\User\UserDashboardComponent;
use App\Http\Livewire\Admin\AdminDashboardComponent;
use Illuminate\Support\Facades\Route;
Route::get('/cart',CartComponent::class)->name('product.cart');
app.php
'aliases' => Facade::defaultAliases()->merge([
// 'ExampleClass' => App\Example\ExampleClass::class,
])->toArray(),
DetailsComponent.php
<?php
namespace App\Http\Livewire;
use App\Models\Product;
use Livewire\Component;
use Cart;
class DetailsComponent extends Component
{
public $slug;
public function mount($slug){
$this->slug=$slug;
}
public function store($product_id,$product_name,$product_price){
Cart::add($product_id,$product_name,1,$product_price)->asseociate('App\Models\Product');
session()->flash('success_message','Item added in Cart');
return redirect()->route('product.cart');
}
cart-component.blade.php
<div class=" main-content-area">
<div class="wrap-iten-in-cart">
#if(session::has('success_message'))
<div class="alert alert-success">
<strong>Success</strong>{{Session::get('success_message')}}
</div>
#endif
#if(Cart::count()>0)
<h3 class="box-title">Products Name</h3>
<ul class="products-cart">
#foreach(Cart::content() as $item)
<li class="pr-cart-item">
<div class="product-image">
<figure><img src="{{('assets/images/products')}}/{{$item->image}}" alt="{{$item->model->name}}"></figure>
</div>
<div class="product-name">
<a class="link-to-product" href="{{route('product.details',['slug'=>$item->model->slug])}}">{{$item->model->name}}</a>
</div>
<div class="price-field produtc-price"><p class="price">Rs.{{$item->model->regular_price}}</p></div>
<div class="quantity">
<div class="quantity-input">
<input type="text" name="product-quatity" value="{{$item->qty}}" data-max="120" pattern="[0-9]*" >
<a class="btn btn-increase" href="#"></a>
<a class="btn btn-reduce" href="#"></a>
</div>
</div>
<div class="price-field sub-total"><p class="price">Rs.{{$item->subtotal}}</p></div>
<div class="delete">
<a href="#" class="btn btn-delete" title="">
<span>Delete from your cart</span>
<i class="fa fa-times-circle" aria-hidden="true"></i>
</a>
</div>
</li>
#endforeach
</ul>
#else
<p>No Item In Cart</p>
#endif
</div>

Retrive ids and check related boxes

Using
Laravel 8.54
Livewire 2.6
Laratrust package for roles and permissions
I want to edit the permissions role like that
RolesEdit.php (livewire component)
<?php
namespace App\Http\Livewire\Admin\Roles;
use App\Models\Role;
use Livewire\Component;
use App\Models\Permission;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Validator;
class RolesEdit extends Component
{
public $data = [];
public $role;
public $selectedIds = [];
public function mount(Role $role)
{
$this->role = $role;
$this->data = $role->toArray();
}
public function update()
{
$this->data['permissions'] = $this->selectedIds;
$validated = Arr::except($this->validatedData(), ['permissions']);
$this->role->update($validated);
$this->role->permissions()->sync($this->data['permissions']);
}
public function validatedData()
{
return Validator::make($this->data, [
'display_name' => 'required',
'description' => 'required',
"permissions" => "required|array|min:1",
"permissions.*" => "required|distinct|min:1",
])->validate();
}
public function render()
{
$permissions = Permission::all();
return view('livewire.admin.roles.roles-edit', compact('permissions'));
}
}
Roles-edit.blade.php
<div class="mt-1">
<label class="form-label">{{ __('site.display_name') }}</label>
<input wire:model="data.display_name" type="text" class="form-control" placeholder="Enter role name" />
</div>
<div class="mt-1">
<label class="form-label">{{ __('site.role_description') }}</label>
<textarea wire:model="data.description" type="text" class="form-control"
placeholder="Enter Description"></textarea>
</div>
<div class="row w-100">
#foreach ($permissions as $permission)
<div class="col-md-3">
<div class="form-check ms-5">
<input wire:model.defer="selectedIds" class="form-check-input" id="{{ $permission->name }}"
value="{{ $permission->id }}" type="checkbox"
{{ $role->permissions->contains($permission->id) ? 'checked' : '' }} />
<label class="form-check-label" for="{{ $permission->name }}">
{{ $permission->display_name }}</label>
</div>
</div>
#endforeach
</div>
When I open roles-edit view I want to check boxes that have $permission->id related to role so I use
{{ $role->permissions->contains($permission->id) ? 'checked' : '' }}
But it did not work … all checkboxes is unchecked
instead using code:
{{ $role->permissions->contains($permission->id) ? 'checked' : '' }}
try this
#if($role->permissions->contains($permission->id)) checked #endif
also try to add wire:key directive to the parent div of the input element
<div class="form-check ms-5" wire:key="input-checkbox-{{ $permission->id }}">
I suggest you, create an array to retrieve the permissions ids of the role
public $permissionsIds = [];
public function mount(Role $role)
{
$this->role = $role;
$this->data = $role->toArray();
$this->permissionsIds = $this->role->permissions()->pluck('id');
}
// in blade
#if(in_array($permission->id,$permissionsIds)) checked #endif

Route [aktivitas.destroy] not defined. (View: C:\xampp\htdocs\TA\resources\views\aktivitas\index.blade.php)

I Try Made Crud Can't defined aktivitas.destroy
index.blade.php
<div class="bs-bars pull-left">
<a href="{{ route('pegawai.create') }}"class="btn btn-primary btn-md">
Tambah
</a>
<a href="{{ url('pegawai-pdf') }}" class="btn btn-success btn-md">
<i class="fas fa-file-pdf"></i> Data Aktivitas
</a>
</div>
#foreach($ar_judul as $jdl)
<th>{{ $jdl }}</th>
#endforeach
</tr>
</thead>
<tbody>
#foreach ($ar_aktivitas as $akt)
<tr>
<td>{{ $no++ }}</td>
<td>{{ $akt->nama_jenis_anggaran }}</td>
<td>{{ $akt->jenis_anggaran }}</td>
<td>{{ $akt->unt }}</td>
<td>Rp. {{ number_format($akt->jumlah_anggaran,2,',','.') }}</td>
<td>{{ $akt->peg }}</td>
<td>{{ $akt->tgl_aktivitas }}</td>
<td>
#if(!empty($akt->foto))
<img src="{{asset('img')}}/{{ $akt->foto }}" width="70px" height="70px">
#else
<div class="icon text-black bg-violet">
<i class="fas fa-tired"></i>
</div>
#endif
</td>
<td>
<form method="POST" action="{{ route('aktivitas.destroy',$akt->id)}}">
<div class="icon">
<a href="{{ route('aktivitas.show',$akt->id) }}" >
<div class="icon bg-blue">
<i class="fas fa-eye"></i>
</div>
</a>
<a href="{{ route('aktivitas.edit',$akt->id) }}" class="">
<div class="icon bg-green">
<i class="fas fa-pen"></i>
</div>
</a>
#csrf
#method('DELETE')
<button type="submit"
class="btn-danger btn-circle btn-sm"
onclick="return confirm('Yakin diHapus?')">
<div class="icon bg-red">
<i class="fas circle fa-trash"></i>
</div>
</button>
AktivitasController.php Controller
class AktivitasController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$ar_aktivitas = DB::table('aktivitas')
->join('unit', 'unit.id', '=', 'aktivitas.unit_id')
->join('pegawai', 'pegawai.id', '=', 'aktivitas.pegawai_id')
->select('aktivitas.*', 'unit.nama AS unt', 'pegawai.nama AS peg')
->get();
return view('aktivitas.index', compact('ar_aktivitas'));
}
public function create()
{
//arahkan ke form input data baru
return view('aktivitas.form');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//validasi data
$validator = Validator::make(request()->all(),[
'nama_jenis_anggaran'=>'required',
'jenis_anggaran'=>'required',
'unit_id'=>'required',
'jumlah_anggaran'=>'required',
'pegawai_id'=>'required',
'tgl_aktivitas'=>'required',
'keterangan'=>'image|mimes:jpg,jpeg,png,gif|max:2048',
],[
'nama_jenis_anggaran.required'=>'Nama Jenis Anggaran Wajib untuk diisi',
'jenis_anggaran.required'=>'Jenis Anggaran Wajib untuk dipilih',
'unit_id.required'=>'Unit Wajib untuk dipilih',
'jumlah_anggaran.required'=>'Jumlah Anggaran Wajib untuk dipilih',
'pegawai.required'=>'Pegawai Wajib untuk diisi',
'tgl_aktivitas.required'=>'Tanggal Wajib untuk diisi',
'keterangan.image'=>'Ektensi File Foto Hanya Boleh .jpg, .png, .gif',
'keterangan.max' =>'File Foto Melebihi 2048 KB',
])->validate();
//2. proses upload,dicek pas input ada upload file/tidak
if(!empty($request->foto)){
/*
$request->validate([
'foto' => 'image|mimes:jpg,jpeg,png,giff|max:2048',
]);
*/
//$fileName = $request->nip.'.'.$request->foto->extension();
$fileName = $request->nip.'.jpg';
$request->foto->move(public_path('img'), $fileName);
}else{
$fileName = '';
}
//1. tangkap request form
DB::table('aktivitas')->insert(
[
'pegawai_id'=>$request->pegawai_id,
'nama_jenis_anggaran'=>$request->nama_jenis_anggaran,
'jenis_anggaran'=>$request->jenis_anggaran,
'jumlah_anggaran'=>$request->jumlah_anggaran,
'tgl_aktivitas'=>$request->tgl_aktivitas,
'keterangan'=>$request->$fileName,
'unit_id'=>$request->unit_id,
]
);
//landing page
return redirect ('/aktivitas');
}
public function show($id)
{
$ar_aktivitas = DB::table('aktivitas')
->join('unit', 'unit.id', '=', 'aktivitas.unit_id')
->join('pegawai', 'pegawai.id', '=', 'aktivitas.pegawai_id')
->select('aktivitas.*', 'unit.nama AS unt', 'pegawai.nama AS peg')
->where('aktivitas.id','=',$id)
->get();
return view('aktivitas.index', compact('ar_aktivitas'));
}
public function edit($id)
{
//tampilkan form untuk menampilkan
//data lama yg mau diedit sebanyak 1 baris data
$data = DB::table('aktivitas')->where('id',$id)->get();
return view('aktivitas/form_edit',compact('data'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//1.proses ubah data
DB::table('aktivitas')->where('id',$id)->update(
[
'pegawai_id'=>$request->pegawai_id,
'nama_jenis_anggaran'=>$request->nama_jenis_anggaran,
'jenis_anggaran'=>$request->jenis_anggaran,
'jumlah_anggaran'=>$request->jumlah_anggaran,
'tgl_aktivitas'=>$request->tgl_aktivitas,
'keterangan'=>$request->keterangan,
'unit_id'=>$request->unit_id,
]
);
//landing page ke detail pemasukan
return redirect ('/activity'.'/'.$id);
}
public function destroy($id)
{
//ambil isi kolom foto lalu hapus file fotonya
//di folder img
//$foto = DB::table('aktivitas')->select('keterangan')->where('id','=',$id)->get();
//foreach($foto as $f){
// $namaFile = $f->foto;
//}
//File::delete(public_path('img/'.$namaFile));
///hapus data
DB::table('aktivitas')->where('id',$id)->delete();
//landing page ke hal pegawai / index.blade.php
return redirect ('/activity');
}
}
You can add:
Route::delete('aktivitas','AktivitasController#destroy');
Add on your routes/web.php

How to set class to child element inside v-for loop

I need some help, I have v-for loop which outputs elements of array referenceDetailsDocumentsData, I need to check at the same time if the id of this element exists in another array documentsData, in this case I need to add custom class to child of this element.
<div class="loading-doc-item"
v-for="referenceDetails in referenceDetailsDocumentsData"
:key="referenceDetails.id">
<div class="loading-doc-show">
{{ referenceDetails.name }}
<span class="upload-status" v-if="checkUploadedDocuments(referenceDetails.id)">
<i class="fa fa-check-circle"></i>
</span>
<span class="upload-status" v-else>
<i class="fa fa-check"></i>
</span>
</div>
</div>
methods() {
checkUploadedDocuments(id) {
return this.documentsData.filter(item => item.id === id);
}
}
In my case, I am getting an error
Error in render: "TypeError: this.documentsData.filter is not a
function"
Your logic is wrong - the method checkUploadedDocuments will return Array but it must return Boolean.
<div class="loading-doc-item"
v-for="referenceDetails in referenceDetailsDocumentsData" :key="referenceDetails.id">
<div class="loading-doc-show">
{{ referenceDetails.name }}
<span class="upload-status">
<i class="fa"
:class="{documentsData && documentsData.length &&
documentsData.findIndex(item => item.id === referenceDetails.id) !== -1
? 'fa-check-circle' : 'fa-check'}"></i>
</span>
</div>
</div>

Forms in Pop yii

I tried to insert a form in Pop up..I used the partial method to redirect it.
I written the pop up code in my controller action.
And I need to insert a form there which I created through GII.
A got an out put but the form is outside the Pop Up..
Can anybody tell me hoe can I Achieve this....
Controller
public function actionpopup($id)
{
//$this->render('/offerEvents/Details',array(
//'model'=>OfferEvents::model()->findByAttributes(array('id'=>$id)), ));
$OfferEventsList = OfferEvents::model()->findAllByAttributes(array('id' => $id));
foreach($OfferEventsList as $Listdata)
{ $titnw=$Listdata['title']; $details=$Listdata['description'];
$discountper=$Listdata['discountper']; $discountperamt=$Listdata['discountperamt'];
$strdaate=$Listdata['startdate']; $enddaate=$Listdata['enddate']; $evoftype=$Listdata['type']; }
$cmuserid=$Listdata['createdby'];
if($Listdata['createdby']==0){ $createdbyname="Admin"; } else { $createdbyname=$Listdata->company->companyname; }
$locationnw=$Listdata->location;
$offrimage=$Listdata->image;
if($offrimage!=""){ $imgUrls=$offrimage; } else { $imgUrls='image-not-available.png'; }
$infowinimgpaths='theme/images/OfferEvents/orginal/'.$imgUrls;
if (file_exists($infowinimgpaths)) { $infowinimgpathSrcs=Yii::app()->baseUrl.'/'.$infowinimgpaths; } else
{ $infowinimgpathSrcs=Yii::app()->baseUrl.'/theme/images/OfferEvents/image-not-available.png'; }
if (Yii::app()->user->id!='' && Yii::app()->user->id!=1){
$subcribeemailid=Yii::app()->user->email; $logsts=1;
$countsubscribe = Newsfeeds::model()->countByAttributes(array('emailid' => $subcribeemailid,'cuserid' => $cmuserid));
} else { $subcribeemailid=''; $countsubscribe=0; $logsts=0; }
$PopupdetailText='<div class="modal-dialog-1">
<div class="modal-content">
<div class="modal-header login_modal_header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h2 class="modal-title" id="myModalLabel">'.$titnw.' </h2>
</div>
<div class="container-1">
<div class="row">
<div class="col-sm-7 detail-text">
<h2 class="title"> ';
if($evoftype==0){ $PopupdetailText.='Offer Price: '.$discountperamt.'
<font style="font-size: 15px;">[ Up To '.$discountper.'% Discount ]</font>'; }
$PopupdetailText.='</h2><p>Details: </p>
<p>'.$details.'</p>
<p>Location: '.$locationnw.'</p>
<p>Expires in: '.$enddaate.'</p>';
if($countsubscribe==0){
$PopupdetailText.='<p>Shared by: '.$createdbyname.'
<button type="button" class="btn btn-success btn-xs" Onclick="subcribefeed('.$logsts.','.$cmuserid.')" >Subscribe NewsFeed</button></p>';
} else {
$PopupdetailText.='<p>Shared by: '.$createdbyname.'
<button type="button" class="btn btn-success disabled btn-xs" >Already Subscribed NewsFeed</button></p>';
}
$PopupdetailText.='<div class="form-group" id="subcribefrm" style="display:none;background-color: #eee; padding: 12px; width: 82%;">
<input type="text" id="subemailid" placeholder="Enter EmailID here" value="'.$subcribeemailid.'" style="width: 100%;" class="form-control login-field">
<br/>
Subscribe Feeds </div> ';
// if($evoftype==0){ $PopupdetailText.='<p>Offer Price:<b> $'.$discountperamt.'</b></p>'; }
$PopupdetailText.='<p>
<img src="'.Yii::app()->baseUrl.'/theme/site/images/yes.png"/>Yes
<img src="'.Yii::app()->baseUrl.'/theme/site/images/no.png"/>No
<img src="'.Yii::app()->baseUrl.'/theme/site/images/comments.png"/>Comments
<img src="'.Yii::app()->baseUrl.'/theme/site/images/share.png"/>Share</p>
<br/>
<form>
<div class="form-group">';
$userComment=new Comments;
$this->renderPartial('/comments/_form', array('model' => $userComment));
$PopupdetailText.='</div>
<div class="form-group">
<input type="text" id="username" placeholder="Enter the below security code here" value="" class="form-control login-field">
</div>
<div class="form-group">
<p><img src="'.Yii::app()->baseUrl.'/theme/site/images/capcha.png"/>Cant read? Refresh</p>
</div>
<div class="form-group">
Post Commets
</div>
</form>
</div>
<div class="col-sm-5">
<img src="'.$infowinimgpathSrcs.'" width="100%"/>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="modal-footer login_modal_footer">
</div>
</div>
</div>
<script>
function subcribefeed(staus,cid)
{
if(staus==0){
$("#subcribefrm").toggle(); }
else { subcribefeedAdd(cid); }
}
function subcribefeedAdd(cid)
{
subusremail=$("#subemailid").val();
var re = /[A-Z0-9._%+-]+#[A-Z0-9.-]+.[A-Z]{2,4}/igm;
if (subusremail == "" || !re.test(subusremail))
{ alert("Invalid EmailID ."); }
else {
postData ={
"email" :subusremail,
"cid" :cid
}
$.ajax({
type: "POST",
data: postData ,
url: "'.Yii::app()->baseUrl.'/newsfeeds/create",
success: function(msg){
if(msg=="Success"){ showdetails('.$id.'); alert("news feed subscribe successfully."); }
else if(msg=="available"){ alert("Already subscribe News Feed for this Commercial user."); }
else { alert("Error ."); }
}
});
}
}
</script> ';
echo $PopupdetailText;
}
renderPartial has a 3rd parameter return. If you set that to TRUE it will return the rendered form instead of echoing it. You can use it as follows:
$PopupdetailText .= $this->renderPartial('/comments/_form', array('model' => $userComment), TRUE);