ASSET::URL not working in external php file in laravel5 - php

I have a php file which is in the name of index.php. In that I have included another page like "xyz.php".
I have included "xyz.php" in index.php using #include('xyz').
When I am trying to include external css and js in xyz using
{{ URL::asset('assets/js/jsfile.js') }}
{{ URL::asset('assets/css/cssfile.css') }}
It is not working. In source it displays as it is.
How can I solve this issue.
index.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Laravel page</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic' rel='stylesheet' type='text/css'>
<link href="{{ URL::asset('assets/netbramha/css/bootstrap.min.css') }}" rel="stylesheet">
<script src="{{ URL::asset('assets/netbramha/js/modernizr.custom.js') }}"></script>
</head>
<body>
#include('home-search')
</body>
</html>
home-search.blade.php
<div class="video-modal">
<img class="lazy-load" data-original="{{ URL::asset('/') }}/assets/netbramha/images/video-img.jpg" src="images/grey.gif" width="598" height="336" alt="" />
</div>

Maybe this will help
{{ URL::asset('/') }}/location of you css/scripts
cheers

You are using blade templating in the xyz.php file. It should be named xyz.blade.php

You have to use helper functions
include(public_path() . '/xyz.php')

Related

Can't reach css files laravel-9

I am building a website. in index page everything works. But I tried to add page. At service page, I can reach the content but it is unstyled.
My index file starts like this
#extends('layouts.frontbase')
#section('title', 'Pasa Law')
#section('content')
#include("home.slider")
My service file is same
#extends('layouts.frontbase')
#section('title', $data->title)
#section('content')
<p>{{$data->detail}}</p>
#endsection
When I open site css and javascript files are okey in index
index page
But when I open service site it has problems with css
service page
Frontbase.blade.php
<html>
<head>
<title>#yield('title')</title>
#yield('head')
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="copyright" content="Kaan Pasa, https://github.com/kaanpasa">
<title>#yield("title")</title>
<link rel="stylesheet" href="assets/css/maicons.css">
<link rel="stylesheet" href="assets/vendor/animate/animate.css">
<link rel="stylesheet" href="assets/css/bootstrap.css">
<link rel="stylesheet" href="{{asset('assets/vendor/owl-carousel/css/owl.carousel.css')}}">
<link rel="stylesheet" href="assets/css/theme.css">
<!-----Slider CSS--->
<link rel="stylesheet" href="/assets/css/owl.theme.default.min.css">
<link rel="stylesheet" href="assets/css/ionicons.min.css">
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body class="bg-light">
#include("home.header")
<div class="container">
#yield('content')
</div>
#include("home.footer")
#yield('foot')
</body>
</html>
If your link is
link rel="stylesheet" href="/css/styles.css"
try
link rel="stylesheet" href="{{ asset('css/styles.css') }}"
and put your css files in the public folder e.g
public|->css|->styles.css

how do i pass value from different link to one view laravel?

So I have this view1.php where I want to pass different values from different links to view2.php.
I manage to pass and get the value, but the css I put in my layout.php just won't work for view2.php.
I don't know where I'm doing it wrong.
Are there another way to pass different values other than this?
view1.php
#extends('layouts.layout')
#section('content')
<div>
OP 6000
OP 10000
OP 20000
</div>
#endsection
web.php
Route::get('/pass/{id}','User\MyController#postID');
MyController.php
public function postID($id) {
return view('user.view2', [
'id' => $id
]);
}
view2.php
#extends('layouts.layout')
#section('content')
<div>
{{$id}}
</div>
#endsection
layout.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<link rel="stylesheet" type="text/css" href="css/materialize.css" media="screen,projection"/>
<link rel="stylesheet" href="css/bootstrap/bootstrap.css">
<link rel="stylesheet" href="css/user.css">
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>
<nav> </nav>
<main class="">
#yield('content')
</main>
<footer> </footer>
#yield('alert')
</body>
<script type="text/javascript" src="js/materialize.min.js"></script>
</html>
Seems the css is not loading in view2.php. You need to use baseurl to load css.
Example : <link rel="stylesheet" href="{{URL::asset('css/user.css')}}">
This issue occurs because when you redirect another view your CSS not load properly.
My advice to you is using the assets method.
<link rel="stylesheet" type="text/css" href="{{ asset('css/materialize.css') }}" media="screen,projection"/>
<link rel="stylesheet" href="{{ asset('css/bootstrap/bootstrap.css') }}">
<link rel="stylesheet" href="{{ asset('css/user.css') }}">
Just because the URL of your view2 are http://something.com/pass/some_id and you are linking stylesheets by css/some_css.css so that, it is searching in the current directory i.e. pass so that, the URLs of the stylesheets are becoming like http://something.com/pass/css/some_css.css. That's an issue.
If you will use /css/some_cs.css, it will try to locate the files from the home directory i.e. the / directory, so the URL will become http://something.com/css/some_css.css and everything will work perfectly.
else, you should use the helper provided by Laravel
{{asset('css/some_css.css')}}
It will generate URL, where the files are located without fail.

Is it possible to add CDN on HTML via a PHP include?

I'm creating a website for homework and it's going to have multiple pages. I'm using bootstrap 4 and for each page, I have to declare a lot of links and scripts on the head of the HTML.
My question is if it's possible to add a single link via HTML or a PHP include so I can use a single line for all the additions and edit them all on a single file.
This is what I have
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="stylesheet.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
I want something like this
<head>
<title> </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="alltheotherlinksandscripts.php">
</head>
Or this
<html>
<head>
<title></title>
<?php
include_once "alllinks.php";
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body> </body>
</html>
You can. Put the header in a separate php file and you can include it in all files.
<head>
<?php include('header.php'); ?>
</head>
Yes, you can set all links (js/css libraries) in one file i.e alllinks.php
and call that file in your <head> part like..
<head>
<?php include('alllinks.php'); ?>
</head>

different stylesheet for different pages in laravel

I'm new to laravel. I have two pages A and B which uses tables. Now in my layout.blade.php I have a link towards only one stylesheet which is affecting both the tables in A and B. I only want it in A and for B I have different set of stylesheet. How do I target the stylesheet to the pages?
You can load css files directly in these views, so A would load one css and B will load another one.
Another way if to use conditional loading in layout.blade.php:
#if (request()->is('pageA'))
// Load CSS for A
#elseif (request()->is('pageB'))
// Load CSS for B
#endif
Usually in this case you should have a master layout that only include global scripts and stylesheets, says layouts/global.blade.php
<!doctype html>
<html lang="en-US">
<head>
<title>Your website</title>
#section('meta')
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
#show
#section('stylesheets')
<link rel="shortcut icon" href="{{asset("favicon.ico")}}" type="image/x-icon"/>
<link type="text/css" rel="stylesheet" href="{{asset("css/global.css")}}"/>
#show
#section('scripts')
<script src="{{url("js/global.js")}}"></script>
#show
</head>
<body>
#yield('content')
</body>
</html>
Then in your page_a.blade.php, you extend it and include your own specific stylesheets:
#extends('layouts/global')
#section('stylesheets')
#parent
<link type="text/css" rel="stylesheet" href="{{url("css/page_a.css")}}"/>
#endsection
#section('scripts')
#parent
<script src="{{url("js/page_a.js")}}"></script>
#endsection
#section('content')
Your page A content
#endsection
I think you may create a section like the following in your view, for example:
#extends('layouts.master')
#section('styles')
<link href="{{asset('assets/css/custom-style.css')}}" />
#stop
Hope this helps you.
You can use sass css for that conditions. In that sass css you can use if and else condition and check variable.
Please refer below link for how to use it.
http://thesassway.com/intermediate/if-for-each-while

CSS not loading in Laravel 5.2

Situation:
I'm creating a web application using Laravel, but for the moment CSS that i created aren't loading.
Folder Structure
Laravel Version
Laravel Framework version 5.2.36
master.blade.php code
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>#yield('title')</title>
<link rel ="stylesheet" href= "{{ URL::secure('src/css/main.css') }}">
#yield('styles')
</head>
<body>
#include('includes.header')
<div class="main">
#yield('content')
</div>
</body>
</html>
Write like this:
<link rel ="stylesheet" href= "{{ asset('src/css/main.css') }}">
Another alternative:-
<link rel="stylesheet" href="{{ url('/') }}./src/css/main.css" type="text/css"/>

Categories