Laravel syntax error put closing tag '}' where it shouldn't be when creating a link - laravel

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
#foreach ($tasks as $task)
<li>
<a href="/tasks/{{ $task->id }}">
{{ $task->body }}
</a>
</li>
}
#endforeach
</ul>
</body>
</html>
This is lesson episode 6 from Laracasts (beginner's section). My code looks exactly like what's being shown on the instructor's screen but I get an extra } after each hyperlink. It took me a while to figure out how he divided the views between folders too. Some pretty good info but the instructor needs to slow down a bit. I probably missed something here too but I've rewinded and rewatched at least 5 times now.

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
#foreach ($tasks as $task)
<li>
<a href="/tasks/{{ $task->id }}">
{{ $task->body }}
</a>
</li>
#endforeach
</ul>
</body>
</html>
Try this. You don't need } after closing tag

Related

How to change the language of layouts using the Laravel localization tool?

I'm using Laravel's localization tool to change the language of my application (English and French). The change of language is done thanks to a select in the navigation bar.
With the official doc I use the routes, the controllers and the blades to change the language of the content of the pages.
However, I can't change the language of the layouts (footer and navbar links). Normally I create routes for my pages and point to the controller that contains the changeLang method. But I can't create route and controller for layouts because layouts concern all pages and therefore all routes. I'm new to Laravel so.. be indulgent :) thank you very much ^^
I've already searched a lot on StackOverflow and I haven't found anything that looks like my problem. Thank you to all of you!
BASIC METHOD (which works well FOR PAGES)
routes/web.php
Route::group([ 'middleware' => 'Language'], function () {
Route::get('/',"\App\Http\Controllers\HomeController#index");
Route::get('/change-language/{lang}',"\App\Http\Controllers\HomeController#changeLang");
});
app/Http/Middlewares/Language
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
class Language
{
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* #return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if(session()->has("lang_code")){
App::setLocale(session()->get("lang_code"));
}
return $next($request);
}
}
app/Http/Controllers/HomeController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
class HomeController extends Controller
{
public function index(){
return view("home");
}
public function changeLang($langcode){
App::setLocale($langcode);
session()->put("lang_code",$langcode);
return redirect()->back();
}
}
resources/views/home.blade.php (data come from resources/lang/en/home (or /fr/home))
#include('layouts/navbar')
<div class="container-fluid ">
<div class=""><img class="presentation-img " src="{{ asset('images/presentation.jpg') }}" alt="myself"></div>
<div class="presentation-paragraph zoomIn">
<h1>{{__("messages.title")}} </h1> <br>
<p class="paragraph">{!! trans('messages.presentation')!!}
</p>
</div>
</div>
#include ('layouts/footer')
<script>
function changeLanguage(lang){
window.location='{{url("change-language")}}/'+lang;
}
</script>
WHAT I HAVE TRIED TO DO FOR LAYOUTS (which doesn't work) (data come from resources/lang/en/navbar (or /fr/navbar))
resources/views/layouts/navbar.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="description" content="Portfolio" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mon Portfolio</title>
<link rel="shortcut icon" sizes="114x114" href="{{ asset('images/favicon.ico') }}">
<!-- Styles -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body class="antialiased">
<nav id="mainNav" class="navbar navbar-expand-lg py-lg-4 navbar-dark" style="padding: 23px 0px;">
<div class="absolute-select">
<select class="absolute-select-select" onchange="changeLanguage(this.value)" >
<option {{session()->has('lang_code')?(session()->get('lang_code')=='en'?'selected':''):''}} value="en">
<img src="{{ asset('images/flags/english.png') }}" />
English
</option>
<option {{session()->has('lang_code')?(session()->get('lang_code')=='fr'?'selected':''):''}} value="fr">
<img src="{{ asset('images/flags/french.png') }}" />
French
</option>
</select>
</div>
<div class="container">
<img class="logo-img " src="{{ asset('images/logo.png') }}" alt="logo ">
<button class="navbar-toggler navbar-toggler-right" data-bs-toggle="collapse" data-bs-target="#navbarResponsive"><span class="navbar-toggler-icon"></span></button>
<div id="navbarResponsive" class="collapse navbar-collapse">
<ul class="navbar-nav flex-grow-1 justify-content-evenly">
<li class="nav-item">
<a class="nav-link" href="/">{{__("navbar.one")}}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/projets">{{__("navbar.two")}}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/competences">{{__("navbar.three")}}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/apropos">{{__("navbar.four")}}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contact">{{__("navbar.five")}}</a>
</li>
</ul>
</div>
</div>
</nav>
<script>
function changeLanguage(lang){
window.location='{{url("change-language")}}/'+lang;
}
</script>
On my page the content is not displayed. I get these navbar links :
Should I create a route/ a controller for layouts? I thought only the script in the blade was enough because the navbar and the footer are included in all pages... But I'm missing something to make it work!
Sorry if my question is a bit long and for my intermediate level of English.
Due to your comment, I think you should log your locale in the blade and send your result here.
like this :
{{ Config::get('app.locale') }}
I think you forgot to define lang
/lang
/en
navbar.php
/fr
navbar.php

Laravel Code isn't applied to web page. How can I fix it?

I'm using Laravel framework for the first time. Writng the code and viewing on web page, it showed the code without applying.
For example,
#if (Route::has('login'))
#auth HOME
#else LOGIN
#if (Route::has('register')) REGISTER
#endif
#endauth
#endif
How can I fix it?
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<div class="flex-center position-ref full-height">
#if (Route::has('login'))
<div class="top-right links">
#auth
Home
#else
Login
#if (Route::has('register'))
Register
#endif
#endauth
</div>
#endif
<div class="content">
<div class="title m-b-md">
Laravel
</div>
<div class="links">
Docs
Laracasts
News
Blog
Nova
Forge
Vapor
GitHub
</div>
</div>
</div>
</body>
</html>
Avobe code is the basic code of Laravel page.
But the problem is the blade template isn't applied.
# or {} is showed just as it is.
(Cause the length of the code is too long I deleted the part of style code.)

Incorrect HTML rendering

We are building a Spring Boot + Thymeleaf App, running on Tomcat 9 where an HTML page :
<!DOCTYPE html>
<html>
<head></head>
<body>
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
</body>
</html>
is being rendered as :
<!DOCTYPE html>
<html>
<head></head>
<body>
<ul>
<li>Coffee</li>
<li>Tea
<ul>
</ul></li><li>Black tea</li>
<li>Green tea</li>
</ul>
<li>Milk</li>
</body></html>
Please suggest as correct rendition of lists is needed for Bootstrap NavBar.

[Vue warn]: Error compiling template:

I have already asked this question already(closed due to inactivity) and I have been trying many different methods to solve it but it still doesn't work. I even try removing all those related to vue inside laravel by following many different kind of website where they all told me to remove the vue dependency. (here is one of the link that I followed, https://mattstauffer.com/blog/removing-all-vue-dependencies-from-laravel/) I even replaced the app.js with a new one created from scratch since in the past I didn't do anything to it
Can somebody please help me, I am stuck in this problem for quite a long time already and I really don't know what to do. All I want is to solve this error "[Vue warn]: Error compiling template:" since it is affecting the navbar in my webpage
I am using laravel framework 5.5.7 and I didn't even update my laravel to get until this vue. And also I don't even recall installing vue into my laravel.
This is the error they given me:
- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.
(found in <Root>)
app.blade.php
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
<div id="app">
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<!-- Collapsed Hamburger -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse" aria-expanded="false">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<html>
<head>
<title>SideBar Menu</title>
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
</head>
<body>
<div id="sidebar">
<ul>
<li>Summary</li>
<li>Deleted Records</li>
<li class="dropdown">
Edit User Information <span class="caret"></span>
<ul class="dropdown-menu forAnimate" role="menu">
<li>Personal Information Edit</li>
<li>Driver License Class Edit</li>
</ul>
</li>
<li class="dropdown">
Evaluation <span class="caret"></span>
<ul class="dropdown-menu forAnimate" role="menu">
<li>Evaluation</li>
</ul>
</li>
</ul>
<div id="sidebar-btn">
<span></span>
<span></span>
<span></span>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#sidebar-btn').click(function(){
$('#sidebar').toggleClass('visible');
});
});
</script>
</body>
</html>
<!-- Branding Image -->
<a class="navbar-brand" href="{{ url('/') }}" style="color: white">
{{ config('app.name', 'Laravel') }}
</a>
</div>
<div class="collapse navbar-collapse" id="app-navbar-collapse">
<!-- Left Side Of Navbar -->
<ul class="nav navbar-nav">
</ul>
<div id="center-text">
<ul class="nav navbar-nav navbar-center" id="nav-center">
<li>
<h3>#yield('title')</h3>
</li>
</ul>
</div>
<!-- Right Side Of Navbar -->
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
#guest
<li>Login</li>
<li>Register</li>
#else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" style="background-color:blue" style="color:white">
<b>{{ Auth::user()->name }}</b> <span class="caret"></span>
</a>
<ul class="dropdown-menu" style="background-color: blue">
<li>
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();" style="background-color: blue" style="color: white">
<b>Logout</b>
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
#endguest
</ul>
</div>
</div>
</nav>
#yield('content')
</div>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>

Dynamic navigation in laravel using jquery and bootstrap?

I am new to Laravel, I am loving it so far and am trying to utilize the blade templating system as much as possible. What I have right now is my navigation existing in the middle of the screen at the root of the site:
and inside of my home.blade.php:
#extends('layouts.master')
#section('title')
#parent
::Home
#stop
#section('content')
<div class="row col-md-8 col-md-offset-2 text-center indexWrapper">
<div class="indexNav">
<ul class="text-right">
<li>Artists</li>
<li>Bulletin</li>
<li>Something</li>
<li>Something</li>
</ul>
</div>
<div class="indexHeading">
<h1 class="indexH1">Mumbler</h1>
</div>
</div>
#stop
and my master.blade.php
<!DOCTYPE html>
<html>
<head>
<title>
#section('title')
#show
</title>
<link href="{{ asset('bower/bootstrap/dist/css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/default.css') }}" rel="stylesheet">
<link href="{{ asset('bower/jquery/dist/jquery.min.js') }}" rel="script">
</head>
<body>
<div class="container">
#section('navigation')
#show
#yield('content')
</div>
</body>
</html>
Now I am also new to Bootstrap, so I apologize for what might be egregious misuse of classes. What I do have though, is a margin of 25% on what wraps this navigation, and when I click on one of the links (I.E. artists), I want that whole navigation to move up (jquery, I can handle that much), and the 'artists' view to appear below. What would be an elegant solution to this? Any resources for a beginner to laravel 4?
Thank you
I believe you should've tagged this as javascript and jquery since blade does not do what you want it to, (move up when someone clicks the link)

Resources