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">
<a href="login1.html" class="active">Login</a><a href="register1.html">Register</a>
</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 --->
<a href="forget1.html">Forget password?</a>
</div>
</form>
<div class="other-links">
<span>Or login with</span><a href="#">Facebook</a><a href="#">Google</a><a href="#">Linkedin</a>
</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