i am quite new to laravel and blade templates , and i am quite confused what should i do in this situation.
I got mutiple tables - cpus table, motherboards table, memory table etc... each table contains information about parts specifications
I'm retrieving single column from a table
$select_columns = [
'cores',
'threads',
'frequency',
'max_frequency',
'l1',
'l2',
'l3',
'thermal',
'tech',
];
$specs = \DB::table('cpus')->select($select_columns)->where('slug' , $slug)->first();
The information about specification and value should be displayed like this.
<table>
<tbody>
<tr>
<td>Specificiation</td>
<td>value</td>
</tr>
<tr>
<td>Specification</td>
<td>value</td>
</tr>
// other specifications
</tbody>
</table>
I could easily output all tables rows with foreach loop using 1 template.
#foreach ($specs as $spec => $value)
<tr>
<td>{{$spec}} </td>
<td>{{$value}} </td>
</tr>
#endforeach
but the {{spec}} - specificarions needs to be in different language, and i can't use
select(column as newvalue)
because there are letters like 'Ā Ļ Ņ Ž ' and code would loook really weird if i would do that
So i guess the question is what exactly should i do about it?
Should i make each table a new template and display data like this?
<tr>
<td>Specification</td>
<td>{{$specs->value}}</td>
</tr>
<tr>
<td>Specification1</td>
<td>{{$specs->value1}}</td>
</tr>
I'm quite lost here.
Thanks in advance.
Personally I would not make a separate template for each table. Dry, lazy developer and all those things.
I think the localization functionality from Laravel might be a good fit here. You could use the keys from your array as keys in your translation files. Perhaps something like this:
#foreach ($specs as $spec => $value)
<tr>
<td>{{trans('specs.' . $spec)}} </td>
<td>{{$value}} </td>
</tr>
#endforeach
And inside you resources/lang/fr/specs.php file you you could do something like:
return [
'cpu' => 'çpû',
// ...
];
You could even add additional texts (some sort of description or whatever) based on those keys to enrich your tables even more. And if you ever decide to translate your website to another language you're already halve way there, you just have to add a folder for your new language and copy and translate those files there.
Related
How to make php codeigniter codes to make feature to 'sort table' by user needs.
I have set the query in models on my final web project (https://github.com/HermesED/KharismaArt)
Models: Project_Model
Controller: admin(dir)/pengurus
View: Admins(dir)/pengurus_admin.php
Sorry for directing you guys to github, because Idk how to post codes here.
It works on sorting table field 'NIM' or ('Student_Id') in English. But that's "automatic" from coding. I want to make manual feature, like in sorting table things just like MS Excel
But I really don't have idea to create feature for sorting table in views.
Can anyone help? Or do you have some useful website for references?
Try editable jquery it's provide sorting, pagination and search feature.
https://editor.datatables.net/examples/inline-editing/simple
i hope it's works
As the number of rows of each table is less than 100 the easiest way to implement sortable table is by using a free javascript plugin named Dynatable.The simple way to implement Dynatable your project is given below.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Dynatable/0.3.1/jquery.dynatable.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Dynatable/0.3.1/jquery.dynatable.min.js"></script>
<script>
$(document).ready(function(){
$('#myTable').dynatable();
});
</script>
<table id="myTable" class="table table-bordered">
<thead>
<tr>
<th><b>NIM</b></th>
<th><b>Nama Lengkap</b></th>
<th><b>Program Studi</b></th>
<th><b>Angkatan</b></th>
<th><b>Status</b></th>
<th><b>Delete</b></th>
</tr>
</thead>
<tbody>
<?php
foreach($anggota as $pengurus){
?>
<tr>
<td><?php echo $pengurus->nim;?></td>
<td><?php echo $pengurus->namalengkap;?></td>
<td><?php echo $pengurus->programstudi;?></td>
<td><?php echo $pengurus->angkatan;?></td>
<td><?php echo $pengurus->status;?></td>
<td>
<a href="<?php echo base_url('admins/pengurus/hapus/'.$pengurus->nim)?>">
<i class="fa fa-times fa-2x" aria-hidden="true"></i>
</a>
</td>
</tr>
<?php }?>
</tbody>
</table>
If the number of rows increases more than 100 then Data Tables is recommended. But its implementation needs to break your codes and it is a little complicated and not recommended for tables with small sizes.
Remember you need to import jquery before using it and for every table assign different table ids. Clicking on any table header field will sort the table according to that field.
I try to execute select * from articles where category_id=1 in laravel eloquent model as below.
$articles = Article::where('category_id', '=', $id)->get();
And i pass this to my view file by using compact method as below.
return view('homeview.index', compact('articles'));
And i use this $articles variable in foreach loop and print each article's title in view file. But the thing is when i try to execute this, my view file is refreshing continuously and incrementing the same div class which i used to print the article titles. I tried to use above code as raw query also. It also generates the same issue.
below is my view file.
<tbody>
#foreach($articles as $article)
<tr>
<td><img src="{{asset('/img_thumbs/'.$article->img_thumb)}}"></td>
<td class="-align-center">
<h4>{{$article->title}}</h4>
<p>{{$article->sub_paragraph}}</p>
</td>
<tr>
#endforeach
</tbody>
Please help me to solve this.
The bottom line is, THere's an error in your HTML.
You are opening <tr> but not closing it.
<tbody>
#foreach($articles as $article)
<tr>
<td><img src="{{asset('/img_thumbs/'.$article->img_thumb)}}"></td>
<td class="-align-center">
<h4>{{$article->title}}</h4>
<p>{{$article->sub_paragraph}}</p>
</td>
</tr> <!-- HERE -->
#endforeach
</tbody>
i used some java scripts for my application. That repeating thing happening because one script file. After i comment it, my page is working fine. I used some template called inspinia and it is happening because inspinia.js file.
So, I found this cool PHP script on the web called Listr. It makes your Index directories much prettier. I also noticed someone made a version specifically for Bootstrap, but opted not to use it (I don't want something over complicated, nor do I want to compile things).
So, I went along with the original Listr, added and removed a couple things to make it mobile friendly, and here is the result:
So, for whatever reason, only the first line shows up properly under Name. I really don't know why; I've tried several placements of <table>, <th>, and <tr>... none of my methods seem to work.
Here is my code: http://pastebin.com/uHSJhFyq (sorry, it's minified! you'll have to unminify it to read it :/)
Try this for the <tbody>:
<tbody>
<?if($folder_list):?>
<?foreach($folder_list as $item):?>
<tr>
<th><a href=<?=$item['name']?>/><?=$item['name']?></a></th>
<th><?=$item['size']['num']?><?=$item['size']['str']?></th>
<th><?=time_ago($item['mtime'])?> ago</th>
</tr>
<?endforeach;?>
<?endif;?>
<?if($file_list):?>
<?foreach($file_list as $item):?>
<tr>
<th><a href=<?=$item['name']?>.<?=$item['ext']?>><?=$item['name']?>.<?=$item['ext']?></a></th>
<th><?=$item['size']['num']?><?=$item['size']['str']?></th>
<th><?=time_ago($item['mtime'])?> ago</th>
</tr>
<?endforeach;?>
<?endif;?>
</tbody>
I want created a PDF with more than one site. I have following with PHPPdf and Twig (as example):
<pdf>
<dynamic-page>
<table>
<tr>
<td>1.</td>
<td>Some header</td>
</tr>
<tr>
<td>1.1</td>
<td>Some subheader</td>
</tr>
<tr>
<td> </td>
<td>Relay long text here........</td>
</tr>
</table>
</dynamic-page>
</pdf>
Now I have the problem that the table part with the long text will write in some cases (when there is not enough place on the site) completely set on the next page in the PDF. But I want that it write as much text as possible on the current page and split than the table with the following text to the next site. Is there a way to do that?
I need some help. I am working on a backend of a website and I want to create functions where I can re-use the same code instead of duplicating it.
So I will have certain "sections" that contain information, such as:
getQuickInfo
function getQuickInfo() {
echo '
<div class="portlet">
<div class="portlet-header">
<h4>Quick Info</h4>
</div>
<div class="portlet-content">
<table cellspacing="0" class="info_table">
<tbody>
<tr>
<td class="value">'.getCount("total_users").'</td>
<td class="full">Total Users</td>
</tr>
<tr>
<td class="value">'.getCount("count_open_requests").'</td>
<td class="full">Open Support Requests</td>
</tr>
</tbody>
</table>
</div>
</div>
';
}
Now I know I am approaching this the wrong way, that's why I am posting this question. But that is just an example of a Quck Info section I would like to re-use on other pages, so I can sitck it wherever I want and just do getQuickInfo()
For this example, that function works fine. I would like suggestions on a better way to do it, and also for some other sections it won't be that easy it will have some Mysql queries and grabbing information from a database, which I can't store that within an echo.
How does everyone else accomplish stuff like this?
My main goal is to be able to output sections wherever I would like:
getQuickInfo()
getAdminNotes()
getSupportRequests()
etc.
Thanks!
Much as I am loathed to mix raw HTML with PHP code in templates, I know others disagree with me and this is one place where it might be a valid use.
So you would create a file that looks like this:
quickinfo.php
<div class="portlet">
<div class="portlet-header">
<h4>Quick Info</h4>
</div>
<div class="portlet-content">
<table cellspacing="0" class="info_table">
<tbody>
<tr>
<td class="value"><?php echo getCount("total_users"); ?></td>
<td class="full">Total Users</td>
</tr>
<tr>
<td class="value"><?php echo getCount("count_open_requests"); ?></td>
<td class="full">Open Support Requests</td>
</tr>
</tbody>
</table>
</div>
</div>
...and in you main page, you can just do:
include('quickinfo.php');
You can easily adapt this to use the result of queries. You would simply perform the query in the main page, and assign the results to a named variable. Then in the template page you use the data in the named variable to generate the page. This means that you can use the same code to generate different results based on different queries - as long as the result are held in the same named variable.
If you're using php 5 you should considered using PHP's object orientation support.
http://php.net/manual/en/language.oop5.php
This way you can create a class which has methods that print out stuff and hold values and then instantiate this class and call it's methods as needed.
I'm no php guru, but maybe you should create separate .php files for each of those sections (something like quickinfo.php, adminnotes.php, etc) put your html layout inside, and maybe even the php functions you need (or you could put them in a separate file, this depends on whether the logic you need is too complex, if it's fairly simple you can put everything in the same file)
Then you would do something like include('quickinfo.php') wherever you want to use those sections.