How to make dynamic #yield in laravel? - php

I want to make #yield('dynamic') to load different pages like single page application in laravel.
Route:
Route::get(
'/front-office-setup/{setup_type}',
'AdmissionFrontOfficeSetupController#index'
)->name('frontofficesetupview');
Controller:
public function index($setup_type)
{
$data['setup_type'] = $setup_type;
return view('frontoffice::frontofficesetup.frontofficesetup', $data);
}
View:
<div class="row">
<div class="col-md-3">asdf</div>
<div class="col-md-4">asdf</div>
<div class="col-md-5"> #yield('{{$setup_type}}')</div>
</div>
Section:
#extends('frontoffice::frontofficesetup.frontofficesetup')
#section('visitor-purpose')
sdfasd
#endsection
But it doesn't render or show in #yield('{{$setup_type}}')
Is there any way to do this?
Edit part*
Also i have already included a #yield type of things in view file
#extends('backend.master.master')
#section('content')
<div class="row">
<div class="col-md-3">asdf</div>
<div class="col-md-4">asdf</div>
<div class="col-md-5"> #yield($setup_type)</div>
</div>
#endsection

#yield is already started PHP tag <?php. SO no need to mention braces again{{}}. Simply try #yield($setup_type) It will work perfectly.

Related

How to embed forms to another website using laravel

I have a two projects using laravel framework. I have a form for project 1 that I want to embed on my project 2.
Here is my FormController in project 1
public function show(Form $form)
{
return view('formbuilder.render', compact('form'))->render();
}
View on project 2 where I want to embed the form on project 1
#extends('layouts.app')
#section('content')
div class="card rounded-0">
<div class="card-body">
<script type="text/javascript" src="https://route/for/first-project-form"></script>
</div>
</div>
#endsection
I want to imitate how jot form works. https://www.jotform.com/help/34-Embedding-a-Form-to-a-Web-Page.
How do I achieve this?
Using an iframe it's just this simple:
#extends('layouts.app')
#section('content')
div class="card rounded-0">
<div class="card-body">
<iframe src="https://route/for/first-project-form"></iframe>
</div>
</div>
#endsection
If you really want to use a javascript file to load the iframe (can't see any reason why, but let's do it):
Create a javascript file:
const container = document.getElementById('form-container')
const iframe = document.createElement("iframe");
iframe.setAttribute("src", "https://route/for/first-project-form");
iframe.style.width = "640px";
iframe.style.height = "480px";
container.appendChild(iframe);
In project 2:
#section('content')
<div class="card rounded-0">
<div class="card-body">
<div id="form-container"></div>
</div>
</div>
<script src="http//link/to/javascript/file"></script>
#endsection

question mark in the url with laravel

i'm learning laravel for now , i'm trying to build a crud application how i got the url with a question mark how i can remove it from the url
the url that i got is like ..../blogs?1
here is the view
#extends ('layouts.app')
#section('content')
<div class="row">
#foreach($blogs as $blog)
<div class="col-md-6">
<div class="card">
<div class="card-header">
{{$blog -> title}}
</div>
<div class="card-body">
{{$blog->content}}
</div>
</div>
</div>
</div>
#endforeach
#endsection
<?php
Route::get('/', function () {
return view('welcome');
});
Route::name('blogs_path')->get('/blogs','BlogController#index');
Route::name('create_blog_path')->get('/blogs/create','BlogController#create');
Route::name('store_blog_path')->post('/blogs','BlogController#store');
Route::name('blogs_path1')->get('/blogs/{id}','BlogController#show');
Route::name('edit_blog_path')->get('/blogs/{id}/edit','BlogController#edit');
how can i fix this , thank you in advance
Because the second argument in route('blogs_path', $blog->id) is parameter.
try this:
Routes:
Route::name('blogs_path')->get('/blogs/{id}/','BlogController#index');
Controller:
public function index(Request $request, $id)
{
...
}
You made a mistake in the routing of the template Blade.
{{ route('blogs_path1', ['id' => $blog->id]) }}

Laracasts tutorial: Is method 'Latest()' removed?

Is the method "latest" used in Controllers removed in newest version of Laravel?
In PHP Storm I get follow error: Method latest() not found in App/Thread.
public function index()
{
//
$threads = Thread::latest()->get();
return view('threads.index', compact('threads'));
}
I'm following a LaraCasts tutorial, and browsing to said page gives me following error. -> forum.test/threads.
ErrorException (E_ERROR)
Method Illuminate\Database\Query\Builder::path does not exist. (View: D:\xampp\htdocs\forum\resources\views\threads\index.blade.php)
As per requested, my view: it is in resources/views/threads/index.blade.php
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Forum Threads</div>
<div class="panel-body">
#foreach ($threads as $thread)
<article>
<h4>
<a href="{{ $thread->path() }}">
{{ $thread->title }}
</a>
</h4>
<div class="body">{{ $thread->body }}</div>
</article>
<hr/>
#endforeach
</div>
</div>
</div>
</div>
</div>
#endsection
Also, my routes.
<?php
Route::get('/', function () {
return view('welcome');
});
Route::resource('threads', 'ThreadController');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
The error is not related to the code you posted. Method Illuminate\Database\Query\Builder::path does not exist.. You are calling somewhere path method which does not exist.
To answer your question, method latest() is still present in the (currently) newest version of Laravel 5.6:
https://laravel.com/api/5.6/Illuminate/Database/Query/Builder.html#method_latest
My guess would be you have an incorrect config of the Thread model relationships. Most probably you did not define path() relationship.
See this answer to similar question: https://stackoverflow.com/a/37934093/1885946

Blank page on laravel 5

I just try to create a profile page i create a Route like this:
Route::get('profile/{id}/{name}','ProfileController#index');
and the index function like this :
public function index($id,$name)
{
$user = \App\User::find($id);
return view('pages.profile',compact('user'));
}
profile view:
#extends('app')
#section('content')
<div class="container" style="margin-top: 50px;padding: 30px;">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="proPic"><img src="{{user->image}}" class="img-responsive" alt="Image"></div>
</div>
</div>
</div>
#endsection
but when I lunch the link i get a blank page
If you have a default installation, you probably need to have:
#extends('layouts.app')
instead of
#extends('app')
and change
{{user->image}}
to
{{ $user->image }}
Your code looks clean, a blank page can occur when laravel doesn't displays errors. I'd recommand you to :
1- Check the server response (HTTP code, content...)
2- Check your logs, maybe you'll discover a problem of configuration

Laravel 5 other routes show 404

i have been working with laravel 4 for a long time without problem and now i am depping in the laravel 5, so i found some frustrating bugs that i dont know how to fix, here the code.
route
Route::get('/', 'HomeController#index');// works
Route::get('home', 'HomeController#home');//dont work
//Route::get('/home', 'HomeController#home');//still doesn't work
Controller
public function index()
{
return view('home');//it works
}
public function home()
{
return view('home');// it does not work :(
}
the home.blade.php
#extends('app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Home</div>
<div class="panel-body">
You are logged in!
</div>
</div>
</div>
</div>
</div>
#endsection
At the browser
http://mailing_creator.dev/ << it open the welcome page normal
http://mailing_creator.dev/home <<< it show 404 not found :(
Any idea?
I found the solution !! I just have to uncomment the
"LoadModule setenvif_module modules/mod_setenvif.so"
on apache httpd.conf, i am using wamp server and the "rewrite module" is disabled i just have to enable it and it will works

Categories