That's my controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Spieler;
class SpielerController extends Controller
{
public function getSpieler(Request $request){
$spielID = $request->get('spielID');
$spielerOutput = Spieler::where('spielPlanID', '=', $spielID)->get();
return view('spieler')->with('alleSpieler', $spielerOutput);
}
}
here you can see my view which I will trigger
#extends('app')
#section('contentSpieler')
<h1>Spieler</h1>
#if(count($alleSpieler) > 0)
#foreach($alleSpieler as $teamSpieler)
{{ $teamSpieler->note }}
#endforeach
#endif
#endsection
And here is my main index/app page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dateneingabe</title>
<link rel="stylesheet" href="/css/app.css">
<script src="{{ asset('/js/jquery-3.2.1.min.js') }}"></script>
</head>
<body>
<div class="container">
<h1>Spiele und Spieler AJAX - Drop Down</h1>
<div class="col-lg-4">
#yield('contentSpiel')
</div>
<div class="col-lg-4">
#yield('contentSpieler')
</div>
</div>
</body>
</html>
When my controller is going to trigger i get back this in my console
<script src="http://localhost:8000/js/jquery-3.2.1.min.js"></script>
</head>
<body>
<div class="container">
<h1>Spiele und Spieler AJAX - Drop Down</h1>
<div class="col-lg-4"></div>
<div class="col-lg-4">
<h1>Spieler</h1> 2.5 Blasdasd
</div>
</div>
</body>
</html>
But I want only that {{ $teamSpieler->note }} should appear in my index/app page in the part #yield('contentSpieler'). What is wrong with my code? The correct value of note 2.5 is in the html console output but at the moment I don't know why there is no output on my index/app page?
if your master view file location is view->index->app.blade.php then
your view file should be like this
#extends('index.app')
#section('contentSpieler')
<h1>Spieler</h1>
#if(count($alleSpieler) > 0)
#foreach($alleSpieler as $teamSpieler)
{{$teamSpieler->note}}
#endforeach
#endif
#endsection
here your master view file location should be correct to extend it in your view file
Related
I am trying to build a search query to use the user's search input (gene name) and return the gene location and symbol from a JSON file I loaded in.
My Site Controller for the JSON input:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SiteController extends Controller
{
public function index()
{
$results = file_get_contents("http://ftp.ebi.ac.uk/pub/databases/genenames/hgnc/json/locus_groups/protein-coding_gene.json");
$data = json_decode($results, true);
dd($data);
}
}
My Search Controller for the search function:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SearchController extends Controller
{
public function search(Request $request){
// Get the search value from the request
$search = $request->input('search');
// Search in the name column from the data table
$data = data::query()
->where('name', 'LIKE', "%{$search}%")
->get();
// Return the search view with the results compacted
return view('search', compact('data'));
}
}
My routes:
<?php
use Illuminate\Support\Facades\Route;
//use App\Http\Controllers\Controller;
use App\Http\Controllers\SiteController;
Route::get('/data', [SiteController::class, 'index']);
Route::get('search', [SearchController::class, 'search']);
Route::get('/', function () {
return view('welcome');
});
And my welcomeblade:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Geisinger</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/1866062af8.js" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="{{ asset('/styles.css') }}" >
</head>
<body>
<img src="{{ asset('/Geisinger_logo.jpg') }}" alt="Geisinger Logo">
<h1> Geisinger Gene Search </h1>
<div class="container my-8 py-5 px-5 mx-5">
<!-- Search input -->
<form action="{{ route('search') }}" method="GET">>
<input type="search" class="form-control" placeholder="Search Gene Name" name="search">
<button type="submit">Search</button>
</form>
<div class="d-grid gap-2 col-6 mx-auto">
<button class="btn btn-outline-dark" type="button">Search <i class="fa-solid fa-magnifying-glass"></i></button>
</div>
<br>
<br>
<h2>Results <i class="fa-solid fa-square-poll-horizontal"></i></h2>
<!-- List items -->
<?php
#if($data->isNotEmpty())
#foreach ($data as $data)
<ul class="list-group mt-3">
<li class="list-group-item">{{ $data->name }}<</li>
<li class="list-group-item">{{ $data->location }}</li>
<li class="list-group-item">{{ $data->symbol }}</li>
</ul>
#endforeach
#else
<div>
<h2>No Gene found</h2>
</div>
#endif
?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
</body>
</html>
I keep getting "route 'search' not defined" and "syntax error unexpected token "if"". Thank you for your help!
You can only access the route() method on named routes. In your web.php file, you must give your search route the name search before you can access it via route('search')
In you web.php change:
Route::get('search', [SearchController::class, 'search']);
to this:
Route::get('search', [SearchController::class, 'search'])->name('search');
Please visit the docs to learn more.
below is my App/Http/Livewire/Test.php file
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Test extends Component
{
public $name = 'mike';
public function render(){
return view('livewire.test');
}
public function clickTest(){
$this->name = 'Joe';
}
}
below is my resources/views/livewire/test.blade.php
<div>
hello {{$name}}
</div>
and below is my resources/views/test.blade.php
<html>
<head>
<title>test page</title>
#livewireStyles
<script src="{{ asset('js/app.js') }}"></script>
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
</head>
<body>
<div>
<livewire:test /> //this line is working fine
<button wire:click="clickTest">test</button> //this line is not working
</div>
#livewireScripts
</body>
</html>
I am able to get hello mike on page load but when I click on the test button it's not changing to Joe. When I checked on my network tab, it looks like the click event is not even triggered and it's not able to reach clickTest() function
Your button needs to be moved into the component:
<div>
hello {{$name}}
<button wire:click="clickTest">test</button>
</div>
how to create a function to fetch variables, retrieve them, and access them on the preview page, getting data from a user by the related id in another table?
I need to create a function that looks for the parameter passed by url in the database, more specifically in the table "company", column "name"
the user types company / name in the address bar and laravel should search for this name and find it (if any), with that name in hand, I need it sent to the view page, where it will load bootstrap classes from the personalite table, that is related to the user through the id, I've tried everything, but I don't have much experience
I found this code that does not have much to do with my question, but it was the closest I came, but I didn't copreendi very well, in the end, it didn't work out and I need to finish my project :(
public function retorna_disciplina($id)
{
$prontuario = session('prontuario');
$cargo = session('cargo');
if($cargo == "P")
{
$disciplina = DB::table('oferecimento_disciplina')
->where('id_professor','=', $prontuario)
->where('dsa', '=', $id)
->first();
if(count($disciplina)>0)
{
$postagens = DB::table('postagens')
->where('dsa', '=', $id)
->get();
return view('disciplinas.disciplina')->with([
'disciplina' => $disciplina,
'postagens' => $postagens
]);
}
else{
Redirect::to('/perfil')->withErros("A disciplina não existe ou você não tem permissão de acesso");
}
}
}
I created a route and it seems to work well
Route::get('/company/{name}', "company/index_controller#search_base_home(name)");
I created a model, a controller and 2 views, 1 if the laravel finds the name and another if not (a search page)
my problem is really creating the function, I'm not getting
tell me what i need to do to put this into practice i would be very grateful for the help
There may be something wrong with the code, disagreements or something, sorry if that is the case, just an example for you to understand my question better
Right now I'm trying hard with this here, but nothing, I don't know, doesn't seem to get the url name
$this->validate($request, [
'name' => 'required|unique:company|name',
]);
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
the view code is this (companybase_lg.blade.php)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>iofrm</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://brandio.io/envato/iofrm/html/css/fontawesome-all.min.css">
<link rel="stylesheet" type="text/css" href="https://brandio.io/envato/iofrm/html/css/iofrm-style.css">
<link rel="stylesheet" type="text/css" href="https://brandio.io/envato/iofrm/html/css/iofrm-theme1.css">
</head>
<body>
<div class="form-body">
<div class="website-logo">
<a href="index.html">
<div class="logo">
<img class="logo-size" src="images/logo-light.svg" alt=""><!--- db class here --->
</div>
</a>
</div>
<div class="row">
<div class="img-holder"><!--- db class here --->
<div class="bg"></div>
<div class="info-holder">
</div>
</div>
<div class="form-holder"><!--- db class here --->
<div class="form-content">
<div class="form-items">
<h3>Get more things done with Loggin platform.</h3>
<p>Access to the most powerfull tool in the entire design and web industry.</p>
<div class="page-links">
LoginRegister
</div>
<form>
<input class="form-control" type="text" name="username" placeholder="E-mail Address" required><!--- db class here ---><!--- db class here --->
<input class="form-control" type="password" name="password" placeholder="Password" required><!--- db class here --->
<div class="form-button">
<button id="submit" type="submit" class="ibtn">Login</button> <!--- db class here --->
Forget password?
</div>
</form>
<div class="other-links">
<span>Or login with</span>FacebookGoogleLinkedin
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://brandio.io/envato/iofrm/html/js/jquery.min.js"></script>
<script src="https://brandio.io/envato/iofrm/html/https://brandio.io/envato/iofrm/html/js/popper.min.js"></script>
<script src="https://brandio.io/envato/iofrm/html/js/bootstrap.min.js"></script>
<script src="https://brandio.io/envato/iofrm/html/js/main.js"></script>
</body>
</html>
FINAL PART
I tried to get the data to fill in with the classes, but returns nothing related to the name, I don't know if I made a mistake somewhere ...
#foreach($companies as $company)
<div class="{{ $companies->personalite->div_class_1 }}"></div>
<div class="{{ $companies->personalite->div_class_2 }}"></div>
<div class="{{ $companies->personalite->div_class_3 }}"></div>
<div class="{{ $companies->personalite->div_class_4 }}"></div>
#endforeach
so I need to take div_class_1 which is in the personalite table and put in div
each user has their classes in this table and is related to it by an ID number, I created a column "name" in the table to do the test but so far nothing
I don't understand the whole question. But I can answer this part of your question.
Question : I need to create a function that looks for the parameter passed by url in the database, more specifically in the table "company", column "name"
Route
Route::get('companies/{name}', 'CompaniesController#searchByName');
Controller
public class CompaniesController extends Controller
{
public function searchByName($name)
{
$company = Company::where('name', $name)->first();
return view('your_blade_view', compact('company'));
}
}
I have a folder in View:
resources -> view
- layouts
+ master.blade.php
- partials
+ footer.blade.php
+ header.blade.php
- news
+ show.blade.php
+ list.blade.php
- apartment
+ show.blade.php
My code in master.blade.php:
<head>
<script src="{{{ URL::asset('js/theme.min.js')}}}"></script>
</head>
<body>
<div class="main-container">
#include('partials.header')
#yield('content')
#include('partials.footer')
</div>
</body>
In news>show.blade.php:
#extends('layouts.master')
#section('content')
<div class="show-news">show all news at here</div>
#stop
In apartment>show.blade.php:
#extends('layouts.master')
#section('content')
<div class="show-apartment">show all apartment at here</div>
#stop
In HTML file have structure like:
header
content
- show slider image
- show list news
- show list apartment
footer
Because all file is define with section('content').
I don't know how to arrange display position of `section('content') correctly with my HTML file.
I think it should be like:
In news>show.blade.php: #section('news')
In apartment>show.blade.php: #section('apartment')
In master.blade.php:
<head>
<script src="{{{ URL::asset('js/theme.min.js')}}}"></script>
</head>
<body>
<div class="main-container">
#include('partials.header')
#yield('news')
#yield('apartment')
#include('partials.footer')
</div>
</body>
But I see on almost project don't using like this.
You can create another layout page that extends master page like this
master.blade.php
<head>
<script src="{{{ URL::asset('js/theme.min.js')}}}"></script>
</head>
<body>
<div class="main-container">
#include('partials.header')
#yield('content')
#include('partials.footer')
</div>
</body>
newlayout.blade.php
#extends('master')
#section('content')
#yield('news')
#yield('appartments')
#endsection
And you can use this layout for pages like you described, for another you can use master
This is master.blade.php placed in views folder
<html ng-app="planner">
<head>
<title>MeetUp Planner</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/master.css" type="text/css">
</head>
<body ng-controller="MainController">
<div class="container" ng-controller="MainController">
<div class="row row-centered planner-block">
<div class="col-md-12">
<div class="col-md-5 col-centered col-min form-area">
<div class="row row-centered">
#yield('signup')
</div>
</div>
</div>
</div>
</div>
<script src="js/master.js"></script>
</body>
</html>
This is forms/signup.blade.php place in views folder
#extends('master')
#section('signup')
<div class="col-md-11 col-centered form-area-inner">
<span class="form-text">Sign Up</span>
<hr class="seperator"/>
</div>
#stop
This is routes file
<?php
Route::get('/', function () {
return view('master');
});
The yield 'signup' is not wokring, the divs and text are not being show in the master file. What could be the problem?
Directory Structure
resources:
---views->errors
---views->forms->signup.blade.php
---views->vendor
---views->master.blade.php
Using laravel 5.2
That's not how it works. master view will be extended when you'll use forms.signup view:
Route::get('/', function () {
return view('forms.signup');
});
If you want to include some view into master view, you should use #include() clause.
your route file will be
<?php
Route::get('/', function () {
return view('forms.signup');
});
?>
change the location of master.blade.php
move it to ---resources/views/layouts/master.blade.php
in your master.blade.php file change this line
#yield('signup') to #yield('content')
reference link : link