Show compare attributes for every product - php

I have a code:
<table class="table table-bordered">
<tr>
<td class="align-middle">
</td>
#forelse($products as $product)
<td>
<div class="comparison-item">
<a class="comparison-item-thumb" href="shop-single.html">
<img src="{{ Voyager::image($product->image) }}" alt="Apple iPhone X">
</a>
<a class="comparison-item-title" href="shop-single.html">{{ $product->title }}</a>
</div>
</td>
#empty
Нет товаров для сравнения
#endforelse
</tr>
#foreach($products as $keyp => $product)
#foreach($product->prodChar as $key => $char)
<tr>
<th>{{ $char->prodCharacter->title }}</th>
<td>{{ $char->value }}</td>
<td>-</td>
<td>-</td>
</tr>
#endforeach
#endforeach
<tr>
<th></th>
<td><a class="btn btn-outline-primary btn-sm btn-block" href="#" data-toast data-toast-type="success" data-toast-position="topRight" data-toast-icon="icon-check-circle" data-toast-title="Product" data-toast-message="successfuly added to cart!">Add to Cart</a></td>
<td><a class="btn btn-outline-primary btn-sm btn-block" href="#" data-toast data-toast-type="success" data-toast-position="topRight" data-toast-icon="icon-check-circle" data-toast-title="Product" data-toast-message="successfuly added to cart!">Add to Cart</a></td>
<td><a class="btn btn-outline-primary btn-sm btn-block" href="#" data-toast data-toast-type="success" data-toast-position="topRight" data-toast-icon="icon-check-circle" data-toast-title="Product" data-toast-message="successfuly added to cart!">Add to Cart</a></td>
</tr>
</table>
Image how this show:
I need write: "-". For product where attribute is none. Now I show all attributes in one column for every product. How I can fix this problem? I need compare keys of arrays?

If I understand correctly, you're talking about this small section here:
#foreach($product->prodChar as $key => $char)
<tr>
<th>{{ $char->prodCharacter->title }}</th>
<td>{{ $char->value }}</td>
<td>-</td>
<td>-</td>
</tr>
#endforeach
So you have two options here:
Option #1: You could compare right in the view as follows:
<td>{{ $char->value?: "-" }}</td>
This would return a - whenever your value is null.
Option #2: You could create a mutator within the ProductChar model as follows:
// ...your product model code
public function getValueAttribute() {
return $this->attributes['value']?: "-";
}
This would make it so that when you call $char->value it will use the value (if not null) or return a - if it is null.

Related

can I use my controller in laravel 8 to delet row that checked in view?

#extends('layouts.app')
#section('content')
<body>
<button class="btn" onclick="deleteSelected()">delete</button>
<table class="table">
<thead>
<tr>
<th scope="col">
<input type="checkbox" id="all" onclick="chkd()">
</th>
<th scope="col">id</th>
<th scope="col">title</th>
<th scope="col">Paragraph</th>
</tr>
</thead>
#foreach ($categories as $categorie)
<tbody>
<tr>
<td>
<input type="checkbox" class="ss" value="{{ $categorie->id }}" onclick="deleteSelected()">
</td>
<th scope="row">{{ $categorie->id }}</th>
<td>{{ $categorie->Title }}</td>
<td>{{ $categorie->Paragraph }}</td>
<form action={{ route('categorie.destroy', $categorie->id) }} method="POST">
#csrf
#method('DELETE')
<td>
<button id="deleteRow" class="btn btn-danger" type="submit" style="display: none">
delete
</button>
</form>
<button class="btn btn-warning"> <a href={{ route('edit', $categorie->id) }}>edit</a> </button>
</td>
</tr>
</tbody>
#endforeach
</table>
</body>
#endsection
that is my view , when I check one of my checkbox and press the button delete I want this row to be deleted or when I checked all I want to delete all row
I think html input must inside the form. How about moving code like this:
#foreach ($categories as $categorie)
<tbody>
<tr>
<td>
<form action={{ route('categorie.destroy', $categorie->id) }} method="POST">
#csrf
#method('DELETE')
<input type="checkbox" class="ss" value="{{ $categorie->id }}" onclick="deleteSelected()">
<button id="deleteRow" class="btn btn-danger" type="submit" style="display: none">
delete
</button>
</form>
</td>
<th scope="row">{{ $categorie->id }}</th>
<td>{{ $categorie->Title }}</td>
<td>{{ $categorie->Paragraph }}</td>
<td><button class="btn btn-warning"> <a href={{ route('edit', $categorie->id) }}>edit</a> </button></td>
</tr>
</tbody>
#endforeach
But, I don't know this is can fix your case or not. I can't see the whole code

Cannot get the list of the modes of an app

I can't do a foreach with my response
I already tried many things but nothing resolved it
/**
* Show the application dashboard.
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$client = new \GuzzleHttp\Client();
$effects = [];
$res = $client->request('GET', 'http://85.171.71.189/get_modes');
$effects = json_decode($res->getBody()->getContents(), true);
return view('base.effects', [ 'effects' => $effects ]);
}
#if($effects)
#foreach($effects as $effect)
<tr>
<td>{{ $effect['mode'] }}</td>
<td>{{ $effect['name'] }}</td>
<td><button class="btn btn-sm btn-primary">Activate</button></td>
<tr>
#endforeach
#else
<tr>
<td colspan="3">No effects found.</td>
</tr>
#endif
I expect that I have a table with all modes inside, but the actual error is
Undefined index: name (View: H:\wamp64\www\scintillement\resources\themes\light\base\effects.blade.php)
Try this:
#forelse ($effects as $effect)
<tr>
<td>{{ isset($effect['mode']) ? $effect['mode'] : '--' }}</td>
<td>{{ isset($effect['name'] ? $effect['name'] : '--' }}</td>
<td><button class="btn btn-sm btn-primary">Activate</button></td>
<tr>
#empty
<tr>
<td colspan="3">No effects found.</td>
</tr>
#endforelse
You should try this:
#if($effects)
#foreach($effects as $effect)
<tr>
#if(isset($effect['mode']))
<td>{{ $effect['mode'] }}</td>
#else
<td>-</td>
#endif
#if(isset($effect['name']))
<td>{{ $effect['name'] }}</td>
#else
<td>-</td>
#endif
<td><button class="btn btn-sm btn-primary">Activate</button></td>
<tr>
#endforeach
#else
<tr>
<td colspan="3">No effects found.</td>
</tr>
#endif
There were some empty rows in get from the http://85.171.71.189/get_modes
You can handle it by adding condition of empty or not before displaying in the table
#if($effects)
#foreach($effects as $effect)
#if(!empty($effect)) // new condition added
<tr>
<td>{{ $effect['mode'] }}</td>
<td>{{ $effect['name'] }}</td>
<td><button class="btn btn-sm btn-primary">Activate</button></td>
<tr>
#endif
#endforeach

How do I disable a specific column in a table with jquery UI sortable?

I have a table with a jquery sortable plugin. You can drag and drop items and than save the new order. My question is, how do i disable columns of the table so i can just drag and drop by the Name column?
HTML code
<table class="table table-bordered" id="users" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Image</th>
<th>Spotify</th>
<th>Instagram</th>
<th>Soundcloud</th>
<th>Facebook</th>
<th>Website</th>
<th>Options</th>
</tr>
</thead>
<tbody id="sortable">
#if(count($rows) > 0)
#foreach($rows as $value)
<tr id="{{ $value->id }}">
<td>{{ $value->name }}</td>
<td>
<img src="{{ $value->getImage('s') }}" >
</td>
<td>{{ $value->spotify_username }}</td>
<td>{{ $value->instagram_username }}</td>
<td>{{ $value->soundcloud_username }}</td>
<td>{{ $value->facebook_username }}</td>
<td>{{ $value->website_url }}</td>
<td class="text-center text-white">
<a data-placement="bottom" title='Additional info about {{ $value->name }}' href='{{ route("artists.view", ["artist" => $value->id]) }}' class="btn btn-sm btn-info tooltip-custom">{{ __('Info') }}</a>
<a data-placement="bottom" title='Edit {{ $value->name }}' href='{{ route("artists.edit", ["artist" => $value->id]) }}' class="btn btn-sm btn-primary tooltip-custom">{{ __('Edit') }}</a>
<a data-placement="bottom" title='Delete {{ $value->name }}' data-name='{{ $value->name }}' data-toggle="modal" data-target="#deleteModal" data-href='{{ route("artists.delete", ["artist" => $value->id]) }}' class="btn btn-sm btn-danger tooltip-custom">{{ __('Delete') }}</a>
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
Script code
$( function() {
$( "#sortable" ).sortable({
update: function (event, ui){
$("#input-new-order-state").val($('#sortable').sortable("toArray"));
$("#form-state").removeClass('d-none');
}
});
$( "#sortable" ).disableSelection();
});
In case someone needs this, i solved it.
I added "handle": ".enable-drag", to the script, and class="enable-drag" to the first td. Now you can drag and drop only by the first column.
$( function() {
$( "#sortable" ).sortable({
"handle": ".enable-drag",
update: function (event, ui){
$("#input-new-order-state").val($('#sortable').sortable("toArray"));
$("#form-state").removeClass('d-none');
}
});
$( "#sortable" ).disableSelection();
} );
<div class="table-responsive">
<table class="table table-bordered" id="users" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Image</th>
<th>Spotify</th>
<th>Instagram</th>
<th>Soundcloud</th>
<th>Facebook</th>
<th>Website</th>
<th>Options</th>
</tr>
</thead>
<tbody id="sortable">
#if(count($rows) > 0)
#foreach($rows as $value)
<tr id="{{ $value->id }}">
<td class="enable-drag">{{ $value->name }}</td>
<td>
<img src="{{ $value->getImage('s') }}" >
</td>
<td>{{ $value->spotify_username }}</td>
<td>{{ $value->instagram_username }}</td>
<td>{{ $value->soundcloud_username }}</td>
<td>{{ $value->facebook_username }}</td>
<td>{{ $value->website_url }}</td>
<td class="text-center text-white">
<a data-placement="bottom" title='Additional info about {{ $value->name }}' href='{{ route("artists.view", ["artist" => $value->id]) }}' class="btn btn-sm btn-info tooltip-custom">{{ __('Info') }}</a>
<a data-placement="bottom" title='Edit {{ $value->name }}' href='{{ route("artists.edit", ["artist" => $value->id]) }}' class="btn btn-sm btn-primary tooltip-custom">{{ __('Edit') }}</a>
<a data-placement="bottom" title='Delete {{ $value->name }}' data-name='{{ $value->name }}' data-toggle="modal" data-target="#deleteModal" data-href='{{ route("artists.delete", ["artist" => $value->id]) }}' class="btn btn-sm btn-danger tooltip-custom">{{ __('Delete') }}</a>
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
</div>

Disable Button if Variants are empty

So I have this forelse that displays all the variants, now what I want to happen is that, if there is no variant. the submit button will be disabled.
<table class="table table-striped">
<thead>
<tr>
<th class="col-sm-5">Name</th>
<th class="col-sm-1">Default?</th>
<th class="col-sm-2 text-right">Retail Price</th>
<th class="col-sm-2 text-right">Quantity</th>
<th class="col-sm-2"></th>
</tr>
</thead>
<tbody>
#forelse ($product->variants as $index => $variant)
<tr>
<td>{{ $variant->name }}</td>
<td>{{ $variant->is_default ? 'Yes' : 'No' }}</td>
<td class="text-right">{{ number_format($variant->retail_price, 2) }} {{ $variant->price_currency }}</td>
<td class="text-right">{{ number_format($variant->quantity, 0) }}</td>
<td>Edit</td>
</tr>
#empty
<tr>
<td colspan="5">No variants found</td>
<?php $varbutton = 'disabled';?>
</tr>
#endforelse
</tbody>
</table>
here is the button
<div class="panel-footer">
<button class="btn btn-default" type="submit"<?php $varbutton; ?>>Update Store</button>
</div>
Is it possible using php and html in the blade alone or do I have to do it in the controller?
You should be using blade in your button:
<div class="panel-footer">
<button class="btn btn-default" type="submit" {{ $varbutton }}>Update Store</button>
</div>
Also please note that there needs to be a space after "submit".
Or, if you don't want that space when the button is not disabled, use:
<?php $varbutton = ' disabled';?>
<div class="panel-footer">
<button class="btn btn-default" type="submit"{{ $varbutton }}>Update Store</button>
</div>

Searching in db using Laravel 4.2

I want to search and display specific data from db and the method that I have made is not retrieving data from database, if i print it just gives a empty array.
My code is as follow:
Controller:
public function search() {
$search = Input::get('search');
if($search){
$query = DB::table('volunteer');
$results = $query ->where('bloodt', 'LIKE', $search) ->get();
//print_r($results); exit;
return View::make('search')->with("volunteer",$results);
}
}
View:
{{Form::open(array('method'=>'POST'))}}
<div class="pull-left col-xs-6 col-xs-offset-0">
{{Form::text('search','',array('placeholder'=>'Search by blood type/zip code/address....','class'=>'form-control','required autofocus'))}}
</div>
<input type="submit" name="search" value="Search" class="btn btn-primary">
<br><br>
{{Form::close()}}
<?php if (isset($results)) { ?>
#foreach($volunteer as $results)
<table class="table table-bordered" style="width: 100%; background-color: lightsteelblue">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>IC/Passport no.</th>
<th>Blood Type</th>
<th>Address</th>
<th>Zip Code</th>
<th>e-mail</th>
<th>Phone no.</th>
<th>Status</th>
</tr>
<tr>
<td>{{ $results->fname }}</td>
<td>{{ $results->lname }}</td>
<td>{{ $results->ic }}</td>
<td>{{ $results->bloodt }}</td>
<td>{{ $results->address }}</td>
<td>{{ $results->zipcode }}</td>
<td>{{ $results->email }}</td>
<td>{{ $results->phone }}</td>
<td>
<div class="btn-group" role="group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
{{ $results->status }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Eligible</li>
<li>Not Eligible</li>
</ul>
</div>
</td>
</tr>
</table>
#endforeach
<?php;
} ?>
Route:
Route::post('search', 'HomeController#search');

Categories