Insert Data into db but show it as a list using Laravel 7 - laravel-7

I can insert data into database but I want to show it as a List. But I don't understand how can I do it. I just stack here doing a project. how can i solve this problem ? please help. Advance Thanks.
This is my Controller Code:
public function courseDetails($id)
{
$courseByID = DB::table('courses')
->join('course_outlines','course_outlines.course_id','=','courses.id' )
->where('courses.id',$id)
->select('courses.*','course_outlines.title1','course_outlines.class1')
->first();
return view('frontEnd.pages.courseDetails',['courseByID'=>$courseByID]);
}
This is my View code:
<div class="card" >
<div class="card-body">
<h2 class="">Course Outline</h2>
<div class="outline_section">
<h4><span class="outline_header">{{$courseByID->title1}}</span></h4>
<ul>
<li>{{$courseByID->class1}}</li>
</ul>
</div>
</div>
</div>
I want to show like this but using just 1 row ..
dd($courseByID) result :
{#386 ▼
+"id": 60
+"course_name": "In a vero pariatur."
+"trainer_name": "Ward Jaskolski"
+"tution_fee": "25590"
+"duration": "9"
+"total_student": null
+"total_class": "11"
+"batch_no": "9"
+"shift": "day"
+"type": "short"
+"hours": "112"
+"start_date": "1979-11-02"
+"deadline": "1998-12-24"
+"status": "1"
+"created_at": null
+"updated_at": null
+"title1": "HTML & CSS"
+"class1": """
* PC De-assembly and Assembly,
* Bus Architecture & Interfaces,
* BIOS, Processor & Motherboard,
* Operating Systems and Installation (Windows XP/7, Ubuntu), Partitioning & Formatting Hard Disk,
* Laptop De-assembly and Assembly,
* Installing adapters,
* Computer Networking Fundamentals,
* Networking Media & Hardware,
* Diagnostics and Troubleshooting
* Sharing file within LAN
"""
}

You can do like this :
<div class="card" >
<div class="card-body">
<h2 class="">Course Outline</h2>
<div class="outline_section">
<h4><span class="outline_header">{{$courseByID->title1}}</span></h4>
<ul>
#foreach(str_replace(['""','*'],['',''], explode(",",$courseByID->class1)) as $key => $val)
<li>{{ $val }}</li>
#endforeach
</ul>
</div>
</div>
</div>
Above code tested here

Related

TypeError: device.devices.map is not a function

I put products on the page and then I got an error, I can't figure out who this is connected with.
const {device} = useContext(Context)
91 | </div>
> 92 | <div className="inner-display-collection">
| ^ 93 | {device.devices.map(device =>
94 | <CartGoods device={device}/>
95 | )}
the product itself:
const CartGoodr = ({device}) => {
const history = useHistory()
return(
<div className="inner-display-collection">
<a key={device.id} href="" className="active-cart" onClick={() => history.push(DEVICE_ROUTE + '/' + device._id)} style={{textDecoration: 'none'}}>
<div className="cart-good">
<div className="wrapper-cart">
<img className="foto-cart" src="" alt="" />
<div className="display-info-cart">
<h3 className="text-price-cart" >{`${device.prise}₽`}</h3>
</div>
<div className="display-info-cart">
<h4 className="text-decription-cart">{device.descriptionMine}</h4>
</div>
</div>
</div>
</a>
</div>
)
}
export default CartGoodr
that is, everything should work out, but this error crashes
The problem is that your device.devices object is empty. It must be an array to have access to that .map function, because it is only accessible on the arrays.
If you try to console log device.devices right before mapping elements, then you will see that it outputs rather undefined, null, number or string instead of array
const {device} = useContext(Context)
console.log(device.devices) // here
If that data is fetching through api request then you could add loading property to the device, set it to true before making the API request and when the data is fetched set it to false, then use it like so:
if(device.loading){
return <p>Loading the device...</p>
}
// and here map through the device.devices or any other content of your component

Prestashop 1.7 Hook admin product does not display

I have a module on Prestashop that works on versions 1.6 and 1.7.
In version 1.6, I managed to display an additional field on the product sheet in the bacok office. I wish to do the same for version 1.7, but without success for now ...
I try with the displayAdminProductsMainStepLeftColumnMiddle hook
my controller of the module:
public function displayAdminProductsMainStepLeftColumnMiddle($params) {
$product = new Product($params['id_product']);
$this->context->smarty->assign(array(
'id_product_jshop' => $product->id_product_jshop
)
);
return $this->display(__FILE__, '/views/templates/1.7/admin/jshop.tpl');
The recording of the hook
$this->registerHook('displayAdminProductsMainStepLeftColumnMiddle');
and my view:
<div class="m-b-1 m-t-1">
<h2>{l s='Custom Attribute from module' mod='jshopimport'}</h2>
<fieldset class="form-group">
<div class="col-lg-12 col-xl-4">
<label class="form-control-label">{l s='ID JSHOP' mod='jshopimport'}</label>
<input type="text" name="id_product_jshop" class="form-control" {if $id_product_jshop && $id_product_jshop != ''}value="{$id_product_jshop}"{/if}/>
</div>
</fieldset>
<div class="clearfix"></div>
</div>
Have you an idea what is wrong?
The function must to start with "hook" and
public function hookDisplayAdminProductsMainStepLeftColumnMiddle($params)
and then you registering without hook
$this->registerHook('displayAdminProductsMainStepLeftColumnMiddle');
For information, I found my error.
Before I was done in my install function :
$this->registerHook('displayAdminProductsMainStepLeftColumnMiddle'));
return parent::install();
With this solution, the hook was nor registered !!
The goot practice is :
if (!parent::install()
|| !$this->registerHook('displayAdminProductsExtra')
|| !$this->registerHook('displayAdminProductsMainStepLeftColumnMiddle')) {
return false;
}
It is important to do first
parent::install()

Infinite loop when using value to call function to get data from REST Nodejs

I'm pretty new in the world of angular 2 & nodejs.
Currently I created a service that allows me to make a query through NodeJs that brings information from MySQL.
On that information I want to use a value that allows me to call a function that brings me the name associated with that id to be able to show it.
The idea is to find the name of the company associated with that ID and that is hosted in another table in the database.
When I make the call from the template, I can connect to the REST API but it starts an infinite loop that blocks my browser memory.
What would be the correct way to make this call and get this information.
customers.service.ts
export class customerService {
private serviceUrl = 'http://localhost:3000/customers';
constructor(private http: HttpClient) { }
getCustomers(): Observable<CustomerList[]> {
return this.http.get<CustomerList[]>(this.serviceUrl)
}
getCustomer(id): Observable<CustomerList[]> {
return this.http.get<CustomerList[]>(this.serviceUrl+'/'+id)
}
}
view-budget.component.ts
getCustomerName(_id) {
console.log('ID C:', _id);
this.customerService.getCustomer(_id).subscribe(datos => {
return this.getCustomer = datos;
})
}
view-budget.component.html
<ul>
<li *ngFor="let budget of viewbudget" id="{{budget.id}}">
<h2>{{ budget.date | date:'dd-MM-yyyy' }}</h2>
<p *ngFor="let customer of getCustomerName()">{{(customer.name)}}</p>
<p>Fecha Inicio: {{ budget.startdate | date:'dd-MM-yyyy' }}</p>
<hr>
<div class="price">$ {{budget.statusid}}</div>
</li>
</ul>
While It is indeed possible to solve the issue from the frontend, I think what you're trying to achieve here is more efficiently done with an SQL join on the back end. Then have the data you need with the company name ready for visualization from another API endpoint.
Once you have that, add a new method to your service, call it from the component's ngOnInit, store the result in the component, and vizualize it with :
<ul>
<li *ngFor="let budget of viewbudget" id="{{budget.id}}">
<h2>{{ budget.date | date:'dd-MM-yyyy' }}</h2>
<p *ngFor="let customer of budget.customers">{{(customer.name)}}</p>
<p>Fecha Inicio: {{ budget.startdate | date:'dd-MM-yyyy' }}</p>
<hr>
<div class="price">$ {{budget.statusid}}</div>
</li>
</ul>
If there are many companies per budget,
or :
<ul>
<li *ngFor="let budget of viewbudget" id="{{budget.id}}">
<h2>{{ budget.date | date:'dd-MM-yyyy' }}</h2>
<p>{{(budget.customer.name)}}</p>
<p>Fecha Inicio: {{ budget.startdate | date:'dd-MM-yyyy' }}</p>
<hr>
<div class="price">$ {{budget.statusid}}</div>
</li>
</ul>
If there's only one company (depending on your data models)
It's generally a bad idea to call functions from the template. Each time change detection runs, the function will be called again, which can cause errors like you're seeing.
Instead, create an ngOnInit function, and call it within there:
ngOnInit() {
this.getCustomerName();
}
And amend your template to use the getCustomer variable you've created:
<p *ngFor="let customer of getCustomer">{{(customer.name)}}</p>
This way, the API call will only be made once (when the component is initialised)
view-budget.component.ts
export class ViewBudget implements OnInit {
...
customerMap: any = {};
...
getCustomerName(_id) {
console.log('ID C:', _id);
this.customerService.getCustomer(_id).subscribe(data => {
return this.customerMap[_id] = data;
})
}
}
view-budget.component.html
<ul>
<li *ngFor="let budget of viewbudget; getCustomerName(budget.id)" id="{{budget.id}}">
<h2>{{ budget.date | date:'dd-MM-yyyy' }}</h2>
<p *ngFor="let customer of customerMap[budget.id]">{{(customer.name)}}</p>
<p>Fecha Inicio: {{ budget.startdate | date:'dd-MM-yyyy' }}</p>
<hr>
<div class="price">$ {{budget.statusid}}</div>
</li>
</ul>
this method is not good solution.
you need to handle your backend.
on your backend, you can populate customers using sql join.
so you don't need request to get customers of each budget.

Paging in Umbraco

I'm working in my Umbraco based website, and I have a page that contains objects arranged in a grid, and the amount of objects is getting bigger so I'll need to create pagination to this page. How can I create the pagination?
I'm new with Umbraco and website development, sorry of this is a stupid question.
Thanks!
Have a look here
#if (Model.HasNext || Model.HasPrevious) {
<nav class="pagination" role="pagination">
#if (Model.HasPrevious) {
<a class="newer-posts" href="#Model.PreviousUrl">
<i class="fa fa-chevron-circle-left"></i> Newer
</a>
}
<span class="page-number">Page #(Model.CurrentPageIndex + 1) of
#Model.TotalPages</span>
#if (Model.HasNext) {
<a class="older-posts" href="#Model.NextUrl">
Older <i class="fa fa-chevron-circle-right"></i>
</a>
}
</nav>
}
This code is from Articulate Blog engine (Umbraco plugin). You must create a custom Pager model.

How to get attribute content between a specific class by php

here is a input code:
$str='
<div class="_53d _53q">Not necessary data</div>
<div class="tagWrapper">
<i style="background-image: url(https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-ash4/p206x206/401581_10201210435645736_1028078736_n.jpg);" class="uiMediaThumbImg"></i>
<div class="taggerOverlay hidden_elem"><div class="left blackwash"></div></div>
</div>
<div class="_53d _53q">Not necessary data</div>
<div class="_53d _53q">Not necessary data</div>
<div class="tagWrapper">
<i style="background-image: url(https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-ash3/p206x206/486115_10200477972538937_146909394_n.jpg);" class="uiMediaThumbImg"></i>
<div class="taggerOverlay hidden_elem"><div class="left blackwash"></div></div>
</div>
<div class="_53d _53q">Not necessary data</div>
';
Now i want the output as :
Array
(
[0] => https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-ash4/p206x206/401581_10201210435645736_1028078736_n.jpg
[1] => https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-ash3/p206x206/486115_10200477972538937_146909394_n.jpg
)
I want to get all of the images links in-between the " <div class="tagWrapper"> <i " attributes and discards all of the other contents. Please help me to give a php code.
You should use DomDocument to parse html.
You can improve this code by adding an extra level of searching over the <i> elements, but I thought the <i> tag was uncommon enough.
Once inside the style property, I used string parsing. It should be improved to be more versatile, but this should get you a lot closer to your goal.
$arr = array();
$dom = new DOMDocument;
$dom->loadHTML($str);
foreach ($dom->getElementsByTagName('i') as $node) {
if($node->hasAttribute('style')) {
$nodes = explode(":",trim($node->getAttribute('style')), 2);
if(trim($nodes[0]) === 'background-image') {
$pos = strpos(trim($nodes[1]), "url");
if($pos !== false) {
$arr[] = substr(trim($nodes[1]), 4, -2);
}
}
}
}

Resources