pdf generation with Laravel - laravel-5

I'm using LynX39\LaraPdfMerger to generate my pdf files from a file named pdf.blade.php. When it's a normal html file everything seems to be good but once generate the pdf file everything is wrong and ugly. Is there any way to make the blade looks like the normal html file? You can see the 2 images below. Any help will be appreciated. Thanks.
to generate the file
$pdf = PDF::loadView('layouts.pdf_view', $data);
return $pdf->download('fiche' . '_' . time() . '.pdf');
pdf file
!https://drive.google.com/open?id=1309cGQl8sFPB22vFZTOdseBt-M7rCTjs
html file
!https://drive.google.com/open?id=1oSJFfRkKsraonATJa50ExH3yNN2HcQqH

do one thing change permission of css folder to +750.
then put css path like
<link rel="stylesheet" href="{{ URL::asset('css_public_path') }}" type="text/css" />

Related

How to STR Replace and echo in laravel

Files that are uploaded to my site have their names changed and extention change to bin. So for example a uploaded file will be dfd84848.bin, using the bin file worked fine with modelviewer but im trying to test babylon.js and it doesnt work with .bin only if i change .bin to .glb.
This code {{uploaded_asset($detailedProduct->cad_file)}} provides link like uploads/all/p1YZX9TBc7EmimFx4rXnSFKvVor8EttpOUUpylLL.bin
I want to change .bin to .glb and echo it.
i tried this
#php
$previewfile = uploaded_asset($detailedProduct->cad_file);
$replaced = Str::replace('.bin', '.glb', $previewfile );
#endphp
to show i used this <model url="{$replaced}"> but it never echoed url
Edit
So now that it echos as name.glb it doesnt work because the file doesnt exist on server. When 3d models such as .glb, .gltf are uploaded they are renamed to .bin i dont know why. The uploader is AizUploadController.php
To echo a value you should use double curly braces:
<model url="{{ $replaced }}">
Docs: https://laravel.com/docs/8.x/blade#displaying-data

Concatenating js files in laravel 5.6

I have some js files in my assets and I want to concat them to one app.js file.
This is what I have in my webpack.mix.js file:
mix.js([
'resources/assets/js/bootstrap.js',
'resources/assets/js/popper.js',
'resources/assets/js/jquery.js',
], 'public/js/app.js');
Now I want to use this script in my project :
$(document).ready(function () {
$('#someId').delay(2000).slideUp(300);
});
But its slide up does not work. When I load the 3 scripts in blade file separately, the function works very well but I need to place all scripts in a single file. Can anyone help me please?
Change it from mix.js to mix.scripts.
scripts is the concatenating function you're looking for when dealing with non-module libraries

Blade templating

Is it possible to have the master.blade.php file outside of the template files.
Example below:
views/
master.blade.php
layout/
hello.blade.php
views/layout/hello.blade.php
#extends('layout.master)
I have tried the above but it cannot find the master.blade.php file. So is there a way to refer to a directory above the blade file.
it would be
#extends('master')
the "." in the view names indicate folders. so
#extends('my.long.path.to.template')
would be found in:
/views/my/long/path/to/template.blade.php
layouts don't have to be in a folder called layouts

codeigniter image path

I am a codeignite newbie and tried to add an image in my file under view folder.
I add <img src="../images/myImage.jpg"></img> to my service_view.php. All I can see is a broken link of a small icon.
however, if I change my path to
<img src="../../user_guide/images/myImage.jpg"></img>
I can see the image.
My file system is as follow:
application-
view ->folder (where service_view.php is located)
images -> folder (where myImage.jpg is located)
user_guide-
images ->folder ((where myImage.jpg is located))
Can anyone help me about this? Thanks a lot!
I would suggest storing images in an images folder at the same level as the application folder, instead of trying to mix both PHP code and resources underneath application. Then just link to it like you did to the user guide:
<img src="../../images/myImage.jpg" />
I know more than year has passed since the question was asked but for anyone who comes looking in future, Here is my solution....
I've tried this created a folder images at same level as that of application, in main index.php added a line before last require_once statement.
define('IMAGE_PATH', APPPATH.'../images/');
and used IMAGE_PATH anywhere I wanted to display images.
Hope this helps
I just have an image folder,
domain.com/images
then on the views i just use /images
<img src="<?php echo base_url(); ?>images/image.png" />
and put the images folder outside of the application folder in the same directory
Create an images folder at the same level of the applications folder.
With base_url() you can get the location of your site's base (cfr config).
This is useful because unlike site_url(), you can supply a string to a file, such as an image or stylesheet.
For example:
<img src="<?php echo base_url("/images/icons/stackOverflow.png"); ?>" alt="StackOverflow" title="StackOverflow is the best!" />
This would give you something like: ... src="http://example.com/images/icons/stackOverflow.png" ...
Source: http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
it is better practice to upload the images in a folder that is present in the root or the site folder and use base href in the first line of head tag. then the whole page does not need and http path reference. just use the relative path. as codeigniter run using the index.php file in the root, we should use all the relative path w.r.t that index.php page
on local server try this
<img src="http://localhost/ci/uploads/<?php echo $this->upload->data()['file_name'];?>" width="200px"/>
on live use this
<img src="<?php echo base_url();?>/uploads/<?php echo $this->upload->data()['file_name'];?>" width="200px"/>
put a folder on your root directory such as "assets/images/" and the in your code just use it as
<img src="assets/images/imgname.jpg"></img>
Your file structure should be
-applications
-images
-assets
-Or any folder.
Keep the application folder, images folder, and assets folder inside the basic root folder.
Use when you want to include something from your root folder
FCPATH = C:\xampp\htdocs\your_root_folder\
<img src="<?php echo FCPATH; ?>/images/myImage.jpg" />
<img src="<?php echo base_url('/assests/images/image_name.jpg')?>" alt="">
This is the exact path for codeigniter, don't need write the "../../.." just write the path from assets (folder name)(sibling of application).
base_url gives the path of your project folder, not the path of the view folder inside application folder.

place images/css/js in views folder (codeigniter)

I am developing a small project that has user and admin sides. In my controllers folder there are two folders admin and user. Similarly in my views folder there are two folders admin and user. Both admin and user ends have different templates. I have placed CSS/Images/JS in assets folder that is placed in root folder (parallel to system folder). I do not want to make two different folders in assets folder for admin and user. Instead what i want is to place respective css/js/images in views/admin and views/user folders. This way i can remove assets folder and all html/css/images etc will be in same folder and i will be able to make different themes for user side. Is it possible?? If yes how?? Please guide me in detail.
edit: I want to place admin.css in application/views/admin and user.css in application/views/users
anyone who want to place all css/js/images in views can try this.
for example you want to place css file in views folder you will give CSS file path like this
href="<? echo base_url() ?>application/views/assets/css/admin.css"
now you will get forbidden access error. This error is cause of .htaccess file in application folder. open .htaccess file and copy paste following.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
You are ready to go..
Load the URL helper in the controller.
Then in views you can use
<link rel="stylesheet" href="<?= base_url() ?>assets/css/admin.css" />
<link rel="stylesheet" href="<?= base_url() ?>assets/css/user.css" />
off course change the path to the css file as required.
You can have separate folders then in your controller construct, change $this->load->_ci_view_path = {theme folder}.
Example: I store the templates information in a database table so,
$this->db->where('published', 'Y')->limit(1);
$res = $this->db->get('templates')->result();
$this->load->_ci_view_path = $res[0]->template_folder;
add one folder any name e.g public and add .htaccess file and write allow from all
it means, in this folder your all files and all folder will not give error Access forbidden!
use it like this
<link href="<?php echo base_url(); ?>application/public/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url(); ?>application/public/js/javascript.js"></script>
etc

Resources