Laravel view register not found - laravel

working on someone's code, figuring out where stuff goes, etc.
the error I am getting:
View [register] not found. (View: /Users/striker/bankproject/app/views/frontend/default/pages/profile.blade.php)
I see that the $sections is being passed from the controller to the view.
Here is the route
Route::get('register',['as'=>'register.create','uses'=>'UsersController#create']);
Route::post('register',['as'=>'register.store','uses'=>'UsersController#store']);
Here is the controller
use Forret\Interfaces\UserInterface;
use View;
use Sentry;
class UsersController extends BaseController{
public function __construct(UserInterface $user){
$this->user = $user;
}
public function show($user_id){
$view['title'] = 'Forret - Profile';
$view['auth_navbar'] = 1;
$view['user'] = Sentry::getUser();
$view['sections'] = ["Frontend::components.sections.profile"];
return View::make('Frontend::pages.profile',$view);
}
public function create(){
$view['title'] = 'Forret - Register';
$view['auth_navbar'] = 0;
$view['user'] = [];
$view['sections'] = ['register'];
return View::make('Frontend::pages.profile',$view);
}
}
Here is the view profile.php
#extends('Frontend::layouts.default')
#section('page_styles')
#stop
#section('content')
#foreach($sections as $section)
#include($section)
#endforeach
#stop
#section('page_scripts')
#stop
Here is the view register.php
#extends('Frontend::layouts.default')
#section('page_styles')
#stop
#section('content')
#foreach($sections as $section)
#include("Frontend::components.sections.$section")
#endforeach
#stop
#section('page_scripts')
#stop

Change the #include in the profile template to:
#include("Frontend::components.sections.$section")

Related

Laravel can not pass variable from controller to component

I can not see my variable in component
Controller
class DigitalContentController extends Controller
{
public function productsList(){
$contents = DigitalContent::all();
return view('pages.digitalContents', compact(['contents']));
}
}
digitalContents
#extends('layouts.base')
#section('body')
<x-content-card></x-content-card>
#endsection
Component
#foreach ( $contents ?? [] as $item )
{{ $item->name }}
#endforeach
Even when I echo variable before return view I can see the variable.
class DigitalContentController extends Controller
{
public function productsList(){
$contents = DigitalContent::all();
echo $contents
return view('pages.digitalContents', compact(['contents']));
}
}
Because you've to parse the variable to the component. So it should be:
<x-content-card :contents="$contents"></x-content-card>
Don't forget to add contents to your component class

Parsing data in view layouts laravel 6

I want to make a profile photo on the admin page, this photo is in the layouts.template file, how can I get the $profil to be sent to the layouts.template page?
#if($profil->upload!=null)
<img src="{{asset('backend/assets/img/{{$profil->upload}}.jpg')}}" alt="..." class="avatar-img rounded-circle">
#else
<img src="{{asset('backend/assets/img/mlane.jpg')}}" alt="..." class="avatar-img rounded-circle">
#endif
and i created $profil in UserController
$auth = Auth::user()->id;
$profil = Profil_user::where('user_id',$auth)->first();
how do I get my $profil to be used in layouts.template
You can share variable along all views inside below file
app/Providers/AppServiceProvider.php
public function boot()
{
//Define your user auth call here
if(confition){
$profile_pic = 'admin.png';
} else {
$profile_pic = 'default.png';
}
\View::composer('*', function($view){
$view->with('profile_pic', $profile_pic);
});
}

Method Illuminate\Database\Eloquent\Collection::links does not exist

I created a model relationship between User and Message. I want to implement a list of messages for the authenticated user but I get the following error.
Method Illuminate\Database\Eloquent\Collection::links does not exist
Controller
public function index()
{
$user_id = auth()->user()->id;
$user = User::find($user_id);
return view('message.index')->with('messages', $user->message);
}
Message provider
class message extends Model
{
public function user() {
return $this->belongsTo('App\User');
}
}
User provider
public function message ()
{
return $this->hasMany('App\Message');
}
index.blade.php
#extends('layouts.app')
#section('content')
<h1>messages</h1>
#if(count($messages)>0)
#foreach ($messages as $message)
<div class="well">
<h3>{{$message->user}}</h3>
<small>Written on {{$message->created_at}} </small>
</div>
#endforeach
{{$messages->links()}}
#else
<p> no post found </p>
#endif
#endsection
Error
"Method Illuminate\Database\Eloquent\Collection::links does not exist.(View: C:\xampp\htdocs\basicwebsite\resources\views\message\index.blade.php)"
Check your view blade, that method (links()) only could be used when your data model is implementing paginate() method.
If you dont use paginate(), remove this part:
{{$messages->links() }}
If you are trying to paginate your data when it gets to the view then you need to add the paginate in your controller before passing the data to the view. Example
return $users = Users::select('id','name')->paginate(10);
with that paginate method in your controller, you can call the links method to paginate your object in view as shown below
{{$users->links()}}
hope it helps you
There are 2 ways to resolve this issue:
Either use paginate function while searching data from database:
$users = DB::table('users')->where('id',$user_id)->paginate(1);
Remove links() function from index.blade.php
{{ $messages->links() }}
Remove {{ $messages->links() }} to in your index.blade.php because {{ $messages->links() }} is supported only when you use paginate
You can do something like this in your controller file.
public function index()
{
$messages = Message::all()->paginate(5);
$user_id = auth()->user()->id;
$user = User::find($user_id);
return view('message.index')->with('messages', $messages, $user->message);
}

trying to return a view from database but getting -"Undefined variable error - Laravel 5.2"

Controller,Route and view code is below.
Getting error
trying to return a view from database but getting -"Undefined variable error - Laravel 5.2"
Football.blade.php
#if (isset($football_datas))
#foreach($football_datas as $football_data)
{{$football_data->day}}
</h3>
<div style="height:20px;">
<p class="time-identity" > 14:00</p>
<a href="{{Route('stream')}}" >
<p class="match-identity">{{$football_data->country}} vs {{$football_data->country}}</p>
<p class="live-video-identity"> video </P>
</a>
</div>
#endforeach
#endif
football_dataController.php
class football_datacontroller extends controller
{
public function index(){
$football_datas= DB::table('football_datas')->select('id','country','day')->get();
return view('football',['football_datas'=>$football_datas]);
}
}
routes
Route::post('football', 'football_dataController#index');
Can you try this on your Controller.
return view('football',compact('football_datas'));
Your code
return view('football',['football_datas'=>$football_datas]);
Try
return View::make('football')->with('football_datas', $football_datas);
I hope it helps.
You can use this way for variables, so you wont need to do all them custon changes:
class football_datacontroller extends controller
{
public function index(){
$football_datas= DB::table('football_datas')->select('id','country','day')->get();
$vars['football_datas'] = $football_datas;
return view('football', $vars);
}
}
Then, you can add several "$vars['blabla]' = $blabla" on top of eachother, and all variables will be available in the view with just the {{$football_datas}} or {{$blabla}} in the examples provided.
Example here under on how to have several:
class football_datacontroller extends controller
{
public function index(){
$football_datas= DB::table('football_datas')->select('id','country','day')->get();
$vars['blabla'] = $blabla;
$vars['football_datas'] = $football_datas;
return view('football', $vars);
}
}

Laravel 4 - Method[ ] does not exist

I'm still a novice to Laravel 4 and trying to figure out why I'm getting an error saying that Method [inventoryNotFound] does not exist. It has to do when I am attempting to use the InventoryController#show function.
On my Index page I have a href that I'm trying to send to the show views. The code looks like this:
#foreach($inventory as $item)
<div class="col-md-4 inventory">
<img class="img-responsive" src="{{{$item->image}}}">
<a class="description" href="">{{{$item->title}}}</a>
#foreach($item->size_details as $details)
<p>{{ $details->size }}: {{ $details->price }}</p>
#endforeach
</div>
#endforeach
My show function is:
class InventoryController extends BaseController {
public function index()
{
$inventory = Inventory::all();
return View::make('inventories.index')->with('inventory', $inventory);
}
public function show($id)
{
$inventory = Inventory::find($id);
if(is_null($inventory)){
return $this->inventoryNotFound();
}
return View::make('inventories.show',['inventory' => $inventory]);
}
}
And I have a resource controller as my routes:
Route::resource('inventories', 'InventoryController');
Even when I attempt to run my routes manually, I run into the same problem.
Any ideas as to why?

Resources