webfuelcode

webfuelcode

Member Since 1 Year Ago

Experience Points
9,520
Total
Experience

480 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
58
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 2
9,520 XP
Nov
24
5 days ago
Activity icon

Started a new Conversation Paginate For Posts Under Category

Trying to show the latest posts with pagination.

$subposts = Category::with(['posts', 'children.posts'])->where('id', $category->id)->first();

Tried get(), latest() but sometimes it says property does not found and sometimes collection error.

I have a page designed for subcategory and post list on two columns.

Nov
16
1 week ago
Activity icon

Started a new Conversation How To Loop In Controller For Multiple Files

I have tried different ways but not clear to me.

Basically, I am uploading two images with db column name img1, img2, so how to loop in the controller to avoid repeating the same code.

if($request->hasFile('img1')){
            $filename = time() . '.' . $request->img1->getClientOriginalExtension();
            if($post->img1){
                Storage::disk('my_files')->delete('post_img/' . $post->img1);
            }
            $request->img1->storeAs('post_img', $filename, 'my_files');
            
            $validated['img1'] = $filename;
        }

Above, for $post->img1 and $post->img2

Nov
14
2 weeks ago
Activity icon

Started a new Conversation If Condition In Controller For Multiple Variables

I am trying to upload two images for the post. And using the if statement for checking if the post has an older image.

So here, I am not sure how to use it. I think array would be in use in the place $post->img1.

Please correct it for two or more images.

            if($post->img1){
                Storage::disk('my_files')->delete('post_img/' . $post->img1);
            }
            $request->img1->storeAs('post_img', $filename, 'my_files');
            
            $validated['img1'] = $filename;
        }
Activity icon

Started a new Conversation How To Check And Delete Image From A Post On Updating

I am just trying to clear the storage by deleting unused images the post has, whenever the post is updated.

public function update(Request $request, Post $post)
    {
        $validated = $this->validate($request, [
            'title' => 'required',
            'img1' => 'sometimes|image',
            'category_id' => 'required',
            'description' => 'required'
        ]);

        // Post image upload
        if($request->hasFile('img1')){
            $filename = time() . '.' . $request->img1->getClientOriginalExtension();
            if(__________){
                Storage::disk('my_files')->delete('post_img/' . __________);
            }
            $request->img1->storeAs('post_img', $filename, 'my_files');
            
            $validated['img1'] = $filename;
        }

        $post->update($validated);
        return redirect()->route('post.show', $post->slug)->withMessage('Updated successfully!');
    }

Main part here is, I am not able to make it delete.

// Post image upload
        if($request->hasFile('img1')){
            $filename = time() . '.' . $request->img1->getClientOriginalExtension();
            if(_________){
                Storage::disk('my_files')->delete('post_img/' . _________);
            }
            $request->img1->storeAs('post_img', $filename, 'my_files');
            
            $validated['img1'] = $filename;
        }

if(__________){ Storage::disk('my_files')->delete('post_img/' . __________); } How to check if the post has an image file, and then delete it if the user uploads a new one.

Nov
13
2 weeks ago
Activity icon

Started a new Conversation Post With Image

Saving the post but not the image in the database. File upload works fine.

Please correct it to make the image save in the database.

controller:

public function store(Request $request)
    {
        $validatedData = $this->validate($request, [
            'title'         => 'required|min:3|max:255',
            'img1'         => 'sometimes|image',
            'img2'         => 'sometimes|image',
            'category_id'   => 'required|numeric',
            'description'   => 'required|min:10'
        ]);

        // Post image upload
        if($request->hasFile('img1')){
            $filename = time() . '.' . $request->img1->getClientOriginalExtension();
            $request->img1->storeAs('post_img', $filename, 'my_files');
            
/////////??????????/////////
        }
    
        $validatedData['user_id'] = Auth::id();
    
        $post = Post::create($validatedData);

        return redirect()->route('post.show', ['post' => $post->slug])->withMessage('Post created successfuly!');
    }
Nov
04
3 weeks ago
Activity icon

Replied to Get All Products From Parent Category And It's All Sub-categories

@amrsubzero I stuck in view page with relations.

How to show the subcategory name and its post title...?

Activity icon

Started a new Conversation Trying To Show Posts From Subcategory

I am trying to show the posts from subcategories, not collecting the posts to the parent category. Using the same table for both categories and subcategories.

Category.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $fillable = ['parent_id', 'name'];

    public function children()
    {
      return $this->hasMany('App\Category', 'parent_id');
    }

    public function posts()
    {
        return $this->hasMany('App\Post');
    }
}

How to make a function for the post view?

Nov
03
3 weeks ago
Activity icon

Awarded Best Reply on Display The 5 Sub Categories Of Parent Category

I got it. Just for someone who will need the same.

or, anyone can correct me if I am wrong. But it works for me.

The controller is below, which limits the 5 main categories.

public function posts()
    {
        $posts = Post::latest()->take(5)->get();
        $categories = Category::whereNull('parent_id')->with('children')->latest()->take(5)->get();
        return view('welcome', compact('posts', 'categories'));
    }

And view the page where I added the limitation to show 5 subcategories.

@forelse ($categories as $cat)
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-body">
                            <h4>{{ $cat->name }}</h4>
                                <ul class="list-group list-group-flush">
                                    
                                    @foreach ($cat->children->take(5) as $child)
                                    <li class="list-group-item">
                                        {{ $child->name }} - {{ $child->posts->count() }}
                                    </li>
                                    @endforeach
                                    
                                </ul>
                        </div>
                    </div>
                </div>
            @endforelse

This is what I found. @foreach ($cat->children->take(5) as $child)

Activity icon

Replied to Display The 5 Sub Categories Of Parent Category

I got it. Just for someone who will need the same.

or, anyone can correct me if I am wrong. But it works for me.

The controller is below, which limits the 5 main categories.

public function posts()
    {
        $posts = Post::latest()->take(5)->get();
        $categories = Category::whereNull('parent_id')->with('children')->latest()->take(5)->get();
        return view('welcome', compact('posts', 'categories'));
    }

And view the page where I added the limitation to show 5 subcategories.

@forelse ($categories as $cat)
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-body">
                            <h4>{{ $cat->name }}</h4>
                                <ul class="list-group list-group-flush">
                                    
                                    @foreach ($cat->children->take(5) as $child)
                                    <li class="list-group-item">
                                        {{ $child->name }} - {{ $child->posts->count() }}
                                    </li>
                                    @endforeach
                                    
                                </ul>
                        </div>
                    </div>
                </div>
            @endforelse

This is what I found. @foreach ($cat->children->take(5) as $child)

Nov
02
3 weeks ago
Activity icon

Replied to Display The 5 Sub Categories Of Parent Category

Thanks @sinnbeck But the function above gives me a total of 5 subcategories, not each category and its 5 subcategories.

Category::whereNull('parent_id')->with(['children')->latest()->take(5)->get();

Above shows this:

Category::whereNull('parent_id')->with(['children' =>function ($q) {
    $q->limit(5);
} ] )->latest()->take(5)->get();

Limiting to 5 shows this:

Nov
01
4 weeks ago
Activity icon

Started a new Conversation Display The 5 Sub Categories Of Parent Category

Trying to display limited subcategories of any parent category.

I have made it to show the limited cateogry. How to make is to limit the subcategory?

Controller is here

public function posts()
    {
        $posts = Post::latest()->take(5)->get();
        $categories = Category::whereNull('parent_id')->with('children')->latest()->take(5)->get();
        return view('welcome', compact('posts', 'categories'));
    }

Model is here

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $fillable = ['parent_id', 'name'];

    public function children()
    {
      return $this->hasMany('App\Category', 'parent_id');
    }

    public function posts()
    {
        return $this->hasMany('App\Post');
    }
}

View file is here

@forelse ($categories as $cat)
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-body">
                            <h4>{{ $cat->name }}</h4>
                                <ul class="list-group list-group-flush">
                                    
                                    @foreach ($cat->children as $child)
                                    <li class="list-group-item">
                                        {{ $child->name }} - {{ $child->posts->count() }}
                                    </li>
                                    @endforeach
                                    
                                </ul>
                        </div>
                    </div>
                </div>
            @endforelse
Activity icon

Started a new Conversation Sub Category Post Count On Posts_count And Posts->count()

I just want to know why this happens.

Why {{$child->posts_count}} does not work but {{$child->posts->count()}} works...

As it showed in the documentation here https://laravel.com/docs/7.x/eloquent-relationships#counting-related-models

Category model is here

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $fillable = ['parent_id', 'name'];

    public function children()
    {
      return $this->hasMany('App\Category', 'parent_id');
    }

    public function posts()
    {
        return $this->hasMany('App\Post');
    }
}

Controller is here

public function posts()
    {
        $posts = Post::latest()->take(5)->get();
        $categories = Category::whereNull('parent_id')->with('children')->withCount('posts')->latest()->take(5)->get();
        return view('welcome', compact('posts', 'categories'));
    }

View file is here

@forelse ($categories as $cat)
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-body">
                            <h4>{{ $cat->name }}</h4>
                                <ul class="list-group list-group-flush">
                                    
                                    @foreach ($cat->children as $child)
                                    <li class="list-group-item">
                                        {{ $child->name }} - {{ $child->posts->count() }}
                                    </li>
                                    @endforeach
                                    
                                </ul>
                        </div>
                    </div>
                </div>
            @endforelse
Oct
30
4 weeks ago
Activity icon

Started a new Conversation Subcategory List With Its Parent Category

Trying to list parent category and few subcategories of it. I have one table and it has both categories and subcategories.

category

The controller is something like this:

public function posts()
    {
        $posts = Post::latest()->take(5)->get();
        $cats = Category::where('parent_id', NULL)->latest()->take(5)->get();
        $subcats = Category::where('parent_id', '=', 'id')->take(5)->get();
        return view('welcome', compact('posts', 'cats', 'subcats'));
    }

The view is experimental and not complete

<div class="row">
            @forelse ($cats as $cat)
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-body">
                            {{ $cat->name }}
                            
                        </div>
                    </div>
                </div>
            @empty
                <div class="card">
                    <div class="card-body">
                        There are no posts available yet.
                    </div>
                </div>
            @endforelse
        </div>
Oct
28
1 month ago
Activity icon

Started a new Conversation Using Laravel Permission And Post Policy Together

I am using spatie laravel permission for user roles. For the post edit and delete, I need to check the post owner.

So I have created a policy for the post. But how to use both (spatie and policy) for delete and edit action.

spatie works like this: @can('product-update') post policy works like this: @can('user_own', $post)

I have tried the blade template: https://laravel.com/docs/7.x/authorization#generating-policies

@can('product-update', 'user_own', $post) or @can(['product-update', 'user_own'], $post) do not work.

Do I have to write separately for both or I can check in the same line...

Activity icon

Started a new Conversation Update Does Not Exist

Updating the user role shows

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

Route is:

Route::get('admin_panel/{user}/edit', '[email protected]_edit')->name('adroleedit');
Route::put('admin_panel/{user}', '[email protected]_update')->name('adroleupdate');

Controller is

public function role_edit(User $user)
    {
        //$user = User::find($user);
        $roles = Role::pluck('name','name')->all();
        $userRole = $user->roles->pluck('name','name')->all();
    
        return view('roles.admin.edit_user_role',compact('user','roles','userRole'));
    }

    // Role update
    public function role_update(Request $request, User $user)
    {
        $this->validate($request, [
            'name' => 'required',            
            'roles' => 'required'
        ]);
    
        $input = $request->all();
            
        $user = User::find($user);
        $user->update($input);
        DB::table('model_has_roles')->where('model_id',$user)->delete();
    
        $user->assignRole($request->input('roles'));
    
        return redirect()->route('adusers')->withMessage('User updated successfully');
    }

The view page is

@extends('roles.admin.master')

@section('title', 'Edit user role')
@section('head', 'Edit user role')

@section('contents')
    <div class="container">

        @if (count($errors) > 0)
          <div class="alert alert-danger">
            <strong>Whoops!</strong> There were some problems with your input.<br><br>
            <ul>
               @foreach ($errors->all() as $error)
                 <li>{{ $error }}</li>
               @endforeach
            </ul>
          </div>
        @endif
        
        <div class="row justify-content-center">
            <div class="col-lg-8">
                    <div class="card">
                        <div class="card-header d-flex justify-content-between align-items-center">
                            <h4>Edit New User</h4>
                            <a class="btn btn-warning" href="{{ route('adusers') }}"> Back</a>
                        </div>
                        <div class="card-body">
                            {!! Form::model($user, ['method' => 'PUT','route' => ['adroleupdate', $user]]) !!}
                                    <div class="form-group">
                                        <strong>Name:</strong>
                                        {!! Form::text('name', null, array('placeholder' => 'Name','class' => 'form-control')) !!}
                                    </div>
                                    <div class="form-group">
                                        <strong>Email:</strong>
                                        {!! Form::text('email', null, array('placeholder' => 'Email','class' => 'form-control')) !!}
                                    </div>                                    
                                    <div class="form-group">
                                        <strong>Role:</strong>
                                        {!! Form::select('roles[]', $roles,$userRole, array('class' => 'form-control')) !!}
                                    </div>
                                    <button type="submit" class="btn btn-primary">Submit</button>
                            {!! Form::close() !!}
                        </div>
                    </div>
            </div>
        </div>
        
    </div>
@endsection
Activity icon

Started a new Conversation Updating User Role Shows 404 Error

Route

Route::get('admin_panel/{user}', '[email protected]_edit')->name('adroleedit');
Route::put('admin_panel/update/{user}', '[email protected]_update')->name('adroleupdate');

User editing view

@extends('roles.admin.master')


@section('contents')
    <div class="container">

        @if (count($errors) > 0)
          <div class="alert alert-danger">
            <strong>Whoops!</strong> There were some problems with your input.<br><br>
            <ul>
               @foreach ($errors->all() as $error)
                 <li>{{ $error }}</li>
               @endforeach
            </ul>
          </div>
        @endif
        
        <div class="row justify-content-center">
            <div class="col-lg-8">
                    <div class="card">
                        <div class="card-header d-flex justify-content-between align-items-center">
                            <h4>Edit New User</h4>
                            <a class="btn btn-warning" href="{{ route('adusers') }}"> Back</a>
                        </div>
                        <div class="card-body">
                            {!! Form::model($user, ['method' => 'PUT','route' => ['adroleupdate', $user->id]]) !!}
                                    <div class="form-group">
                                        <strong>Name:</strong>
                                        {!! Form::text('name', null, array('placeholder' => 'Name','class' => 'form-control')) !!}
                                    </div>
                                    <div class="form-group">
                                        <strong>Email:</strong>
                                        {!! Form::text('email', null, array('placeholder' => 'Email','class' => 'form-control')) !!}
                                    </div>                                    
                                    <div class="form-group">
                                        <strong>Role:</strong>
                                        {!! Form::select('roles[]', $roles,$userRole, array('class' => 'form-control')) !!}
                                    </div>
                                    <button type="submit" class="btn btn-primary">Submit</button>
                            {!! Form::close() !!}
                        </div>
                    </div>
            </div>
        </div>
        
    </div>
@endsection

Controller

// Role edit view page
    public function role_edit($id)
    {
        $user = User::find($id);
        $roles = Role::pluck('name','name')->all();
        $userRole = $user->roles->pluck('name','name')->all();
    
        return view('roles.admin.edit_user_role',compact('user','roles','userRole'));
    }

    // Role update
    public function role_update(Request $request, User $user)
    {
        $this->validate($request, [
            'name' => 'required',            
            'roles' => 'required'
        ]);
    
        $input = $request->all();
            
        $user = User::find($user);
        $user->update($input);
        DB::table('model_has_roles')->where('model_id',$user)->delete();
    
        $user->assignRole($request->input('roles'));
    
        return redirect()->route('adusers')->withMessage('User updated successfully');
    }
Oct
22
1 month ago
Activity icon

Started a new Conversation Trying To Show Old Checkbox Value Selected On Edit Page

Using spatie laravel permission package. Trying to show the old value checked on the edit page.

How to use this <input class="form-check-input" type="checkbox" name="permission[]" value="{{ $value->id }}" {{ $value->id == '.......................' ? 'checked' : '' }}>

role controller for edit

public function edit($id)
    {
        $role = Role::find($id);
        $permission = Permission::get();
        $rolePermissions = DB::table("role_has_permissions")->where("role_has_permissions.role_id",$id)
            ->pluck('role_has_permissions.permission_id','role_has_permissions.permission_id')
            ->all();
    
        return view('roles.edit',compact('role','permission','rolePermissions'));
    }

View page

@foreach($permission as $value)
                    <input class="form-check-input" type="checkbox" name="permission[]" value="{{ $value->id }}" {{ $value->id == '....' ? 'checked' : '' }}>
                        <label>{{ $value->name }}</label>
                    <br/>
                    @endforeach
Oct
21
1 month ago
Activity icon

Replied to Trying To Show All The Permissions For A Role

@sinnbeck Creation view file

@extends('roles.admin.master')


@section('contents')
<div class="container">
    <div class="row">
        <div class="col-lg-12 my-2 d-flex justify-content-between align-items-center">
                <h2>Create New Role</h2>
                <a class="btn btn-warning" href="{{ route('roles.index') }}"> Back</a>
        </div>
    </div>


    @if (count($errors) > 0)
        <div class="alert alert-danger">
            <strong>Whoops!</strong> There were some problems with your input.<br><br>
            <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
            </ul>
        </div>
    @endif



    <form action="{{ route('roles.store') }}" method="POST">
        @csrf
        

            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12">
                    <div class="form-group">
                        <strong>Name:</strong>
                        <input type="text" class="form-control" name="name" placeholder="Name">
                        
                    </div>
                </div>
                <div class="col-xs-12 col-sm-12 col-md-12">
                    <div class="form-ckeck">
                        <strong>Permission:</strong>
                        <br/>
                        @foreach($permission as $value)
                        <input class="form-check-input" type="checkbox" name="permission" value="{{ $value->id }}">
                            <label>{{ $value->name }}</label>
                        <br/>
                        @endforeach
                    </div>
                </div>
                <div class="col-xs-12 col-sm-12 col-md-12 text-center">
                    <button type="submit" class="btn btn-primary">Submit</button>
                </div>
            </div>
    </form>
</div>
@endsection
Activity icon

Started a new Conversation Trying To Show All The Permissions For A Role

I am using spatie laravel permission and I do not get why the role does not save all the permissions. When I see the role view page, it shows one permission only.

Below is the rolecontroller

public function create()
    {
        $permission = Permission::get();
        return view('roles.create',compact('permission'));
    }
    
    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'name' => 'required|unique:roles,name',
            'permission' => 'required',
        ]);
    
        $role = Role::create(['name' => $request->input('name')]);
        $role->syncPermissions($request->input('permission'));
    
        return redirect()->route('roles.index')
                        ->with('success','Role created successfully');
    }
    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $role = Role::find($id);
        $rolePermissions = Permission::join("role_has_permissions","role_has_permissions.permission_id","=","permissions.id")
            ->where("role_has_permissions.role_id",$id)
            ->get();
    
        return view('roles.show',compact('role','rolePermissions'));
    }
    
    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $role = Role::find($id);
        $permission = Permission::get();
        $rolePermissions = DB::table("role_has_permissions")->where("role_has_permissions.role_id",$id)
            ->pluck('role_has_permissions.permission_id','role_has_permissions.permission_id')
            ->all();
    
        return view('roles.edit',compact('role','permission','rolePermissions'));
    }
    
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'name' => 'required',
            'permission' => 'required',
        ]);
    
        $role = Role::find($id);
        $role->name = $request->input('name');
        $role->save();
    
        $role->syncPermissions($request->input('permission'));
    
        return redirect()->route('roles.index')
                        ->with('success','Role updated successfully');
    }
Oct
20
1 month ago
Activity icon

Started a new Conversation Setting The Permission To View For Logged User

I am using spatie permission. Here I have code from a tutorial and stuck on giving permission to authenticate users.

Here the middleware used which blocks the user to view the post.

I am trying to make it appear for all. How do I use auth middleware here in the post controller?

function __construct()
    {
         $this->middleware('permission:product-list|product-create|product-edit|product-delete', ['only' => ['index','show']]);
         $this->middleware('permission:product-create', ['only' => ['create','store']]);
         $this->middleware('permission:product-edit', ['only' => ['edit','update']]);
         $this->middleware('permission:product-delete', ['only' => ['destroy']]);
    }
Oct
18
1 month ago
Activity icon

Started a new Conversation Updating The Post Redirects With Id No The Slug

What is wrong here that I see 404 error. I am using slug from `cviebrock/eloquent-sluggable.

Updating redirects with id not the slug...

public function update(Request $request, Post $post)
    {
        $this->validate($request, [
            'title' => 'required',
            'category_id' => 'required',
            'description' => 'required'
        ]);

        $post->update();
        return redirect()->route('post.show', $post->slug)->withMessage('Updated successfully!');
    }

Where the store method works fine and redirects to a single page with slug.

public function store(Request $request)
    {
        $validatedData = $this->validate($request, [
            'title'         => 'required|min:3|max:255',
            //'slug'          => 'required|min:3|max:255|unique:posts',
            //'image'         => 'sometimes|image',
            'category_id'   => 'required|numeric',
            'description'   => 'required|min:10'
        ]);
    
        $validatedData['user_id'] = Auth::id();
        //$validatedData['slug'] = SlugService::createSlug(Post::class, 'slug', $request->title);//Str::slug($validatedData['slug'], '-');
    
        $post = Post::create($validatedData);

        return redirect()->route('post.show', ['post' => $post->slug])->withMessage('Post created successfuly!');
    }
Oct
17
1 month ago
Activity icon

Started a new Conversation Using Cviebrock Sluggable With Validator

I am using cviebrock/eloquent-sluggable slug package for my project and want to use it with validating data. Tell me how to use it...

Where and how to use $slug = SlugService::createSlug(Post::class, 'slug', 'My First Post'); in below...

public function store(Request $request)
    {
        $validatedData = $this->validate($request, [
            'title'         => 'required|min:3|max:255',
            //'slug'          => 'required|min:3|max:255|unique:posts',
            'category_id'   => 'required|numeric',
            'description'   => 'required|min:10'
        ]);
    
        $validatedData['user_id'] = Auth::id();
    
        $post = Post::create($validatedData);

        return redirect()->route('posts.show', ['post' => $post->id])->withMessage('Post created successfuly!');
    }
Oct
16
1 month ago
Activity icon

Replied to Select On Roles, Trying To Get Property 'id'

@michaloravec @automica I am following a tutorial for laravel permission so I came to know about pluck. Would you please describe to me a little bit about it and where/when to use it?

Activity icon

Replied to Select On Roles, Trying To Get Property 'id'

@jlrdw thanks for the suggestion.

Actually, I am still learning laravel and this package. And this code is a part of a tutorial that I found on a blog for v6 and v7. I am using it on my laravel v7 so I am testing it.

Of course, user will not be able to assign roles...this page is only designed for admins only.

Oct
15
1 month ago
Activity icon

Started a new Conversation Select On Roles, Trying To Get Property 'id'

I am working on laravel permission package and stuck on the user creation page for selecting the role.

Trying to get property 'id' of non-object

Controller

public function create()
    {
        $roles = Role::pluck('name','name')->all();
        return view('users.create',compact('roles'));
    }
<select name="role" id="" class="form-control" multiple>
                        <option value="">Select a role</option>
                        <option value="{{ $roles->id }}">{{ $roles->name }}</option>
                    </select>
Oct
06
1 month ago
Activity icon

Replied to 500 Error On Registering New User

Thanks, @loyd ...such a silly mistake it was...a whole day I was messing with the same code ...

Activity icon

Replied to 500 Error On Registering New User

@loyd RegisterController

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use App\Mail\WelcomeMail;
use Illuminate\Support\Facades\Mail;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);

        Mail::to($data['email'])->send(new WelcomeMail($user));

        return $user;
    }
}
Activity icon

Replied to 500 Error On Registering New User

@michaloravec the last line I see in logs...what does it mean

local.ERROR: Connection could not be established with host mail.wall-spot.com :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed {"exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host mail.wall-spot.com :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed at C:\xampp\htdocs\LinkDir\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php:269)
[stacktrace]
#0 [internal function]: Swift_Transport_StreamBuffer->{closure}(2, 'stream_socket_c...', 'C:\\xampp\\htdocs...', 272, Array)
#1 C:\xampp\htdocs\LinkDir\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php(272): stream_socket_client('ssl://mail.wall...', 0, '', 30, 4, Resource id #745)
#2 C:\xampp\htdocs\LinkDir\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php(58): Swift_Transport_StreamBuffer->establishSocketConnection()
#3 C:\xampp\htdocs\LinkDir\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php(143): Swift_Transport_StreamBuffer->initialize(Array)
#4 C:\xampp\htdocs\LinkDir\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Mailer.php(65): Swift_Transport_AbstractSmtpTransport->start()
#5 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(521): Swift_Mailer->send(Object(Swift_Message), Array)
#6 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(288): Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message))
#7 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php(177): Illuminate\Mail\Mailer->send(Object(Illuminate\Support\HtmlString), Array, Object(Closure))
#8 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Support\Traits\Localizable.php(19): Illuminate\Mail\Mailable->Illuminate\Mail\{closure}()
#9 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php(178): Illuminate\Mail\Mailable->withLocale(NULL, Object(Closure))
#10 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(304): Illuminate\Mail\Mailable->send(Object(Illuminate\Mail\Mailer))
#11 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Mail\Mailer.php(258): Illuminate\Mail\Mailer->sendMailable(Object(App\Mail\WelcomeMail))
#12 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Mail\PendingMail.php(122): Illuminate\Mail\Mailer->send(Object(App\Mail\WelcomeMail))
#13 C:\xampp\htdocs\LinkDir\app\Http\Controllers\Auth\RegisterController.php(75): Illuminate\Mail\PendingMail->send(Object(App\Mail\WelcomeMail))
#14 C:\xampp\htdocs\LinkDir\vendor\laravel\ui\auth-backend\RegistersUsers.php(34): App\Http\Controllers\Auth\RegisterController->create(Array)
#15 [internal function]: App\Http\Controllers\Auth\RegisterController->register(Object(Illuminate\Http\Request))
#16 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(54): call_user_func_array(Array, Array)
#17 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('register', Array)
#18 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\Route.php(239): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\Auth\RegisterController), 'register')
#19 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\Route.php(196): Illuminate\Routing\Route->runController()
#20 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\Router.php(685): Illuminate\Routing\Route->run()
#21 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#22 C:\xampp\htdocs\LinkDir\app\Http\Middleware\RedirectIfAuthenticated.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#23 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\RedirectIfAuthenticated->handle(Object(Illuminate\Http\Request), Object(Closure))
#24 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#25 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#26 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(77): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#27 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#28 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#29 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#30 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#31 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(62): Illuminate\Session\Middleware\StartSession->handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))
#32 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#33 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#34 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#35 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#36 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#37 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#38 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\Router.php(687): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#39 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\Router.php(662): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#40 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\Router.php(628): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#41 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Routing\Router.php(617): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#42 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(165): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#43 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#44 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#45 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#46 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#47 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#48 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#49 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#50 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(63): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#51 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#52 C:\xampp\htdocs\LinkDir\vendor\fruitcake\laravel-cors\src\HandleCors.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#53 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Fruitcake\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))
#54 C:\xampp\htdocs\LinkDir\vendor\fideloper\proxy\src\TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#55 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
#56 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#57 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(140): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#58 C:\xampp\htdocs\LinkDir\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(109): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#59 C:\xampp\htdocs\LinkDir\public\index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#60 {main}
"} 
Activity icon

Started a new Conversation 500 Error On Registering New User

The project was fine but suddenly I see 500 error.

I tried to find out but got no fix What could be the possible error I should look for...

Oct
05
1 month ago
Activity icon

Replied to Why Do I See Error On Newly Setup Project On The Web

@snapey I am not getting what the permission here...I have search a lot and found a bunch of different solutions on different laravel forums.

As I mentioned above, the config.php file of bootstrap deleting or renaming solves it. But I do not want it to continue in this. If I sell this project, the new owner should be able to set his site smoothly. This is why my main concern is.

If the config.php file bootstrap/cache/config.php is creating the error, should I delete it and then provide it...As I see the file contains my local system path...

Of course, it is cache but I do not know if it regenerates auto or I have to keep it...

Here is the file, which does have a hardcoded path (C:\xampp\htdocs\...)

<?php return array (
  'app' => 
  array (
    'name' => 'LinkDir',
    'env' => 'local',
    'debug' => true,
    'url' => 'http://localhost',
    'asset_url' => NULL,
    'timezone' => 'UTC',
    'locale' => 'en',
    'fallback_locale' => 'en',
    'faker_locale' => 'en_US',
    'key' => 'base64:3FE95WB0SbxX9vJ8UhBWunLzR9w75qwIejEU726tpNI=',
    'cipher' => 'AES-256-CBC',
    'providers' => 
    array (
      0 => 'Illuminate\Auth\AuthServiceProvider',
      1 => 'Illuminate\Broadcasting\BroadcastServiceProvider',
      2 => 'Illuminate\Bus\BusServiceProvider',
      3 => 'Illuminate\Cache\CacheServiceProvider',
      4 => 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
      5 => 'Illuminate\Cookie\CookieServiceProvider',
      6 => 'Illuminate\Database\DatabaseServiceProvider',
      7 => 'Illuminate\Encryption\EncryptionServiceProvider',
      8 => 'Illuminate\Filesystem\FilesystemServiceProvider',
      9 => 'Illuminate\Foundation\Providers\FoundationServiceProvider',
      10 => 'Illuminate\Hashing\HashServiceProvider',
      11 => 'Illuminate\Mail\MailServiceProvider',
      12 => 'Illuminate\Notifications\NotificationServiceProvider',
      13 => 'Illuminate\Pagination\PaginationServiceProvider',
      14 => 'Illuminate\Pipeline\PipelineServiceProvider',
      15 => 'Illuminate\Queue\QueueServiceProvider',
      16 => 'Illuminate\Redis\RedisServiceProvider',
      17 => 'Illuminate\Auth\Passwords\PasswordResetServiceProvider',
      18 => 'Illuminate\Session\SessionServiceProvider',
      19 => 'Illuminate\Translation\TranslationServiceProvider',
      20 => 'Illuminate\Validation\ValidationServiceProvider',
      21 => 'Illuminate\View\ViewServiceProvider',
      22 => 'App\Providers\AppServiceProvider',
      23 => 'App\Providers\AuthServiceProvider',
      24 => 'App\Providers\EventServiceProvider',
      25 => 'App\Providers\RouteServiceProvider',
    ),
    'aliases' => 
    array (
      'App' => 'Illuminate\Support\Facades\App',
      'Arr' => 'Illuminate\Support\Arr',
      'Artisan' => 'Illuminate\Support\Facades\Artisan',
      'Auth' => 'Illuminate\Support\Facades\Auth',
      'Blade' => 'Illuminate\Support\Facades\Blade',
      'Broadcast' => 'Illuminate\Support\Facades\Broadcast',
      'Bus' => 'Illuminate\Support\Facades\Bus',
      'Cache' => 'Illuminate\Support\Facades\Cache',
      'Config' => 'Illuminate\Support\Facades\Config',
      'Cookie' => 'Illuminate\Support\Facades\Cookie',
      'Crypt' => 'Illuminate\Support\Facades\Crypt',
      'DB' => 'Illuminate\Support\Facades\DB',
      'Eloquent' => 'Illuminate\Database\Eloquent\Model',
      'Event' => 'Illuminate\Support\Facades\Event',
      'File' => 'Illuminate\Support\Facades\File',
      'Gate' => 'Illuminate\Support\Facades\Gate',
      'Hash' => 'Illuminate\Support\Facades\Hash',
      'Http' => 'Illuminate\Support\Facades\Http',
      'Lang' => 'Illuminate\Support\Facades\Lang',
      'Log' => 'Illuminate\Support\Facades\Log',
      'Mail' => 'Illuminate\Support\Facades\Mail',
      'Notification' => 'Illuminate\Support\Facades\Notification',
      'Password' => 'Illuminate\Support\Facades\Password',
      'Queue' => 'Illuminate\Support\Facades\Queue',
      'Redirect' => 'Illuminate\Support\Facades\Redirect',
      'Redis' => 'Illuminate\Support\Facades\Redis',
      'Request' => 'Illuminate\Support\Facades\Request',
      'Response' => 'Illuminate\Support\Facades\Response',
      'Route' => 'Illuminate\Support\Facades\Route',
      'Schema' => 'Illuminate\Support\Facades\Schema',
      'Session' => 'Illuminate\Support\Facades\Session',
      'Storage' => 'Illuminate\Support\Facades\Storage',
      'Str' => 'Illuminate\Support\Str',
      'URL' => 'Illuminate\Support\Facades\URL',
      'Validator' => 'Illuminate\Support\Facades\Validator',
      'View' => 'Illuminate\Support\Facades\View',
    ),
  ),
  'auth' => 
  array (
    'defaults' => 
    array (
      'guard' => 'web',
      'passwords' => 'users',
    ),
    'guards' => 
    array (
      'web' => 
      array (
        'driver' => 'session',
        'provider' => 'users',
      ),
      'api' => 
      array (
        'driver' => 'token',
        'provider' => 'users',
        'hash' => false,
      ),
    ),
    'providers' => 
    array (
      'users' => 
      array (
        'driver' => 'eloquent',
        'model' => 'App\User',
      ),
    ),
    'passwords' => 
    array (
      'users' => 
      array (
        'provider' => 'users',
        'table' => 'password_resets',
        'expire' => 60,
        'throttle' => 60,
      ),
    ),
    'password_timeout' => 10800,
  ),
  'broadcasting' => 
  array (
    'default' => 'log',
    'connections' => 
    array (
      'pusher' => 
      array (
        'driver' => 'pusher',
        'key' => '',
        'secret' => '',
        'app_id' => '',
        'options' => 
        array (
          'cluster' => 'mt1',
          'useTLS' => true,
        ),
      ),
      'redis' => 
      array (
        'driver' => 'redis',
        'connection' => 'default',
      ),
      'log' => 
      array (
        'driver' => 'log',
      ),
      'null' => 
      array (
        'driver' => 'null',
      ),
    ),
  ),
  'cache' => 
  array (
    'default' => 'file',
    'stores' => 
    array (
      'apc' => 
      array (
        'driver' => 'apc',
      ),
      'array' => 
      array (
        'driver' => 'array',
      ),
      'database' => 
      array (
        'driver' => 'database',
        'table' => 'cache',
        'connection' => NULL,
      ),
      'file' => 
      array (
        'driver' => 'file',
        'path' => 'C:\xampp\htdocs\LinkDir\storage\framework/cache/data',
      ),
      'memcached' => 
      array (
        'driver' => 'memcached',
        'persistent_id' => NULL,
        'sasl' => 
        array (
          0 => NULL,
          1 => NULL,
        ),
        'options' => 
        array (
        ),
        'servers' => 
        array (
          0 => 
          array (
            'host' => '127.0.0.1',
            'port' => 11211,
            'weight' => 100,
          ),
        ),
      ),
      'redis' => 
      array (
        'driver' => 'redis',
        'connection' => 'cache',
      ),
      'dynamodb' => 
      array (
        'driver' => 'dynamodb',
        'key' => '',
        'secret' => '',
        'region' => 'us-east-1',
        'table' => 'cache',
        'endpoint' => NULL,
      ),
    ),
    'prefix' => 'linkdir_cache',
  ),
  'cors' => 
  array (
    'paths' => 
    array (
      0 => 'api/*',
    ),
    'allowed_methods' => 
    array (
      0 => '*',
    ),
    'allowed_origins' => 
    array (
      0 => '*',
    ),
    'allowed_origins_patterns' => 
    array (
    ),
    'allowed_headers' => 
    array (
      0 => '*',
    ),
    'exposed_headers' => false,
    'max_age' => false,
    'supports_credentials' => false,
  ),
  'database' => 
  array (
    'default' => 'mysql',
    'connections' => 
    array (
      'sqlite' => 
      array (
        'driver' => 'sqlite',
        'url' => NULL,
        'database' => 'linkdir',
        'prefix' => '',
        'foreign_key_constraints' => true,
      ),
      'mysql' => 
      array (
        'driver' => 'mysql',
        'url' => NULL,
        'host' => '127.0.0.1',
        'port' => '3306',
        'database' => 'linkdir',
        'username' => 'root',
        'password' => '',
        'unix_socket' => '',
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => NULL,
        'options' => 
        array (
        ),
      ),
      'pgsql' => 
      array (
        'driver' => 'pgsql',
        'url' => NULL,
        'host' => '127.0.0.1',
        'port' => '3306',
        'database' => 'linkdir',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
        'prefix' => '',
        'prefix_indexes' => true,
        'schema' => 'public',
        'sslmode' => 'prefer',
      ),
      'sqlsrv' => 
      array (
        'driver' => 'sqlsrv',
        'url' => NULL,
        'host' => '127.0.0.1',
        'port' => '3306',
        'database' => 'linkdir',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
        'prefix' => '',
        'prefix_indexes' => true,
      ),
    ),
    'migrations' => 'migrations',
    'redis' => 
    array (
      'client' => 'phpredis',
      'options' => 
      array (
        'cluster' => 'redis',
        'prefix' => 'linkdir_database_',
      ),
      'default' => 
      array (
        'url' => NULL,
        'host' => '127.0.0.1',
        'password' => NULL,
        'port' => '6379',
        'database' => '0',
      ),
      'cache' => 
      array (
        'url' => NULL,
        'host' => '127.0.0.1',
        'password' => NULL,
        'port' => '6379',
        'database' => '1',
      ),
    ),
  ),
  'filesystems' => 
  array (
    'default' => 'local',
    'cloud' => 's3',
    'disks' => 
    array (
      'local' => 
      array (
        'driver' => 'local',
        'root' => 'C:\xampp\htdocs\LinkDir\storage\app',
      ),
      'public' => 
      array (
        'driver' => 'local',
        'root' => 'C:\xampp\htdocs\LinkDir\storage\app/public',
        'url' => 'http://localhost/storage',
        'visibility' => 'public',
      ),
      's3' => 
      array (
        'driver' => 's3',
        'key' => '',
        'secret' => '',
        'region' => 'us-east-1',
        'bucket' => '',
        'url' => NULL,
      ),
    ),
    'links' => 
    array (
      'C:\xampp\htdocs\LinkDir\public\storage' => 'C:\xampp\htdocs\LinkDir\storage\app/public',
    ),
  ),
  'hashing' => 
  array (
    'driver' => 'bcrypt',
    'bcrypt' => 
    array (
      'rounds' => 10,
    ),
    'argon' => 
    array (
      'memory' => 1024,
      'threads' => 2,
      'time' => 2,
    ),
  ),
  'logging' => 
  array (
    'default' => 'stack',
    'channels' => 
    array (
      'stack' => 
      array (
        'driver' => 'stack',
        'channels' => 
        array (
          0 => 'single',
        ),
        'ignore_exceptions' => false,
      ),
      'single' => 
      array (
        'driver' => 'single',
        'path' => 'C:\xampp\htdocs\LinkDir\storage\logs/laravel.log',
        'level' => 'debug',
      ),
      'daily' => 
      array (
        'driver' => 'daily',
        'path' => 'C:\xampp\htdocs\LinkDir\storage\logs/laravel.log',
        'level' => 'debug',
        'days' => 14,
      ),
      'slack' => 
      array (
        'driver' => 'slack',
        'url' => NULL,
        'username' => 'Laravel Log',
        'emoji' => ':boom:',
        'level' => 'critical',
      ),
      'papertrail' => 
      array (
        'driver' => 'monolog',
        'level' => 'debug',
        'handler' => 'Monolog\Handler\SyslogUdpHandler',
        'handler_with' => 
        array (
          'host' => NULL,
          'port' => NULL,
        ),
      ),
      'stderr' => 
      array (
        'driver' => 'monolog',
        'handler' => 'Monolog\Handler\StreamHandler',
        'formatter' => NULL,
        'with' => 
        array (
          'stream' => 'php://stderr',
        ),
      ),
      'syslog' => 
      array (
        'driver' => 'syslog',
        'level' => 'debug',
      ),
      'errorlog' => 
      array (
        'driver' => 'errorlog',
        'level' => 'debug',
      ),
      'null' => 
      array (
        'driver' => 'monolog',
        'handler' => 'Monolog\Handler\NullHandler',
      ),
      'emergency' => 
      array (
        'path' => 'C:\xampp\htdocs\LinkDir\storage\logs/laravel.log',
      ),
    ),
  ),
  'mail' => 
  array (
    'default' => 'smtp',
    'mailers' => 
    array (
      'smtp' => 
      array (
        'transport' => 'smtp',
        'host' => 'smtp.gmail.com',
        'port' => '587',
        'encryption' => 'tls',
        'username' => '[email protected]',
        'password' => 'johnpaul40BB',
      ),
      'ses' => 
      array (
        'transport' => 'ses',
      ),
      'sendmail' => 
      array (
        'transport' => 'sendmail',
        'path' => '/usr/sbin/sendmail -bs',
      ),
      'log' => 
      array (
        'transport' => 'log',
        'channel' => NULL,
      ),
      'array' => 
      array (
        'transport' => 'array',
      ),
    ),
    'from' => 
    array (
      'address' => NULL,
      'name' => 'LinkDir',
    ),
    'markdown' => 
    array (
      'theme' => 'default',
      'paths' => 
      array (
        0 => 'C:\xampp\htdocs\LinkDir\resources\views/vendor/mail',
      ),
    ),
  ),
  'queue' => 
  array (
    'default' => 'sync',
    'connections' => 
    array (
      'sync' => 
      array (
        'driver' => 'sync',
      ),
      'database' => 
      array (
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
      ),
      'beanstalkd' => 
      array (
        'driver' => 'beanstalkd',
        'host' => 'localhost',
        'queue' => 'default',
        'retry_after' => 90,
        'block_for' => 0,
      ),
      'sqs' => 
      array (
        'driver' => 'sqs',
        'key' => '',
        'secret' => '',
        'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
        'queue' => 'your-queue-name',
        'region' => 'us-east-1',
      ),
      'redis' => 
      array (
        'driver' => 'redis',
        'connection' => 'default',
        'queue' => 'default',
        'retry_after' => 90,
        'block_for' => NULL,
      ),
    ),
    'failed' => 
    array (
      'driver' => 'database',
      'database' => 'mysql',
      'table' => 'failed_jobs',
    ),
  ),
  'services' => 
  array (
    'mailgun' => 
    array (
      'domain' => NULL,
      'secret' => NULL,
      'endpoint' => 'api.mailgun.net',
    ),
    'postmark' => 
    array (
      'token' => NULL,
    ),
    'ses' => 
    array (
      'key' => '',
      'secret' => '',
      'region' => 'us-east-1',
    ),
  ),
  'session' => 
  array (
    'driver' => 'file',
    'lifetime' => '120',
    'expire_on_close' => false,
    'encrypt' => false,
    'files' => 'C:\xampp\htdocs\LinkDir\storage\framework/sessions',
    'connection' => NULL,
    'table' => 'sessions',
    'store' => NULL,
    'lottery' => 
    array (
      0 => 2,
      1 => 100,
    ),
    'cookie' => 'linkdir_session',
    'path' => '/',
    'domain' => NULL,
    'secure' => NULL,
    'http_only' => true,
    'same_site' => 'lax',
  ),
  'view' => 
  array (
    'paths' => 
    array (
      0 => 'C:\xampp\htdocs\LinkDir\resources\views',
    ),
    'compiled' => 'C:\xampp\htdocs\LinkDir\storage\framework\views',
    'expires' => true,
  ),
  'flare' => 
  array (
    'key' => NULL,
    'reporting' => 
    array (
      'anonymize_ips' => true,
      'collect_git_information' => false,
      'report_queries' => true,
      'maximum_number_of_collected_queries' => 200,
      'report_query_bindings' => true,
      'report_view_data' => true,
      'grouping_type' => NULL,
    ),
    'send_logs_as_events' => true,
  ),
  'ignition' => 
  array (
    'editor' => 'phpstorm',
    'theme' => 'light',
    'enable_share_button' => true,
    'register_commands' => false,
    'ignored_solution_providers' => 
    array (
      0 => 'Facade\Ignition\SolutionProviders\MissingPackageSolutionProvider',
    ),
    'enable_runnable_solutions' => NULL,
    'remote_sites_path' => '',
    'local_sites_path' => '',
    'housekeeping_endpoint_prefix' => '_ignition',
  ),
  'trustedproxy' => 
  array (
    'proxies' => NULL,
    'headers' => 30,
  ),
  'tinker' => 
  array (
    'commands' => 
    array (
    ),
    'alias' => 
    array (
    ),
    'dont_alias' => 
    array (
      0 => 'App\Nova',
    ),
  ),
);
Activity icon

Started a new Conversation Using Variable In .env File

I see .env file uses variable. I am not sure if it is the same as we use in blade files.

Suppose I want to set the variable for site address and SMTP details. So the site admin can set it from their admin site setting page.

This cames in mind when I was working on welcome mail where it has a template ready with a button link to the site.

Oct
04
1 month ago
Activity icon

Started a new Conversation Why Do I See Error On Newly Setup Project On The Web

When I upload the script on web server it shows error

Parse error: syntax error, unexpected ':', expecting '{' in /home/wallsaba/......./systemdir/vendor/symfony/polyfill-php80/bootstrap.php on line 23

Updating php version to different and then back to latest soves it and shows the another error

file_put_contents(C:\xampp\htdocs..........\storage\framework/sessions/ILCiQOaRFksYocs2iVl8OQwfqRESMCrtiyQH1fTQ): failed to open stream: No such file or directory

And it solves when the bootstrap config.php file is renamed or deleted...

What is the proper way to fix it. Why should I delete or reset the php version...

Activity icon

Replied to Moving The Posts When Associate Category Is Deleted

Thank you guys, I am done with @michaloravec reply here but I would like to know what @bobbybouwmann @tykus side..

Here the Category.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $fillable = ['name'];

    public function getRouteKeyName()
    {
        return 'name';
    }

    public function links()
    {
        return $this->hasMany(Link::class)->paginate(10);
    }
}

Like.php...

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Link extends Model
{
    protected $fillable=['title', 'user_id', 'category_id', 'url', 'description'];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function category()
    {
        return $this->belongsTo(Category::class);
    }
}
Activity icon

Started a new Conversation Moving The Posts When Associate Category Is Deleted

I just want to move the posts to another category/default/null when its category is deleted.

Because I see the post remains and it shows an error "...trying to get the property "name"...." here the name is from category name.

Currently, I found a laracast post about the same which says this...

public function destroy(Category $category)
    {
        $category->links()->delete();
        $category->delete();
        Link::whereCategoryId($id)->update(['category_id' => null]);

        Session::flash('success', 'The category was successfully deleted.');
        return redirect()->back();
    }

This shows error...

Method Illuminate\Database\Eloquent\Collection::delete does not exist.

Is there something wrong? What is the proper way to get it done?

Oct
03
1 month ago
Activity icon

Started a new Conversation How To Make User Personal Records Simple Optional?

I am using resource in route just to avoid messing up with route name whenever calling. So here I stuck in updating the user details. Trying to make it simple and optional entry.

public function update(Request $request, User $user)
    {
        $this->validate(request(), [
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'password' => 'required|min:6|confirmed'
        ]);

        $user->name = request('name');
        $user->email = request('email');
        $user->password = bcrypt(request('password'));

        $user->save();
        return redirect()->back()->withMessage('Your personal data is successfully edited!');
    }

Suppose I want to let the member just change the password. Do I need to get a separate view page and a separate controller function?

Oct
02
1 month ago
Activity icon

Replied to List With Paginate

@michaloravec I have used it in the AppServiceProvider like this...

view::composer(['links.category'], function($view){
            $view->with('categories', Category::withCount('links')->get());
        });

And the error appears

Method Illuminate\Database\Eloquent\Collection::getRelated does not exist.

Activity icon

Replied to List With Paginate

Thanks for the reply @michaloravec I got the solution for pagination. I got this... in category model

public function links()
    {
        return $this->hasMany(Link::class)->paginate(10);
    }

Another problem I see is the next page shows no category count. I have category names on the left and the post count on each category. But when the next page is clicked, all the post count shows zero.

Activity icon

Replied to List With Paginate

It says

Method Illuminate\Database\Eloquent\Collection::paginate does not exist.

When adding $links = $category->links()->paginate(10);

Activity icon

Replied to List With Paginate

@michaloravec I posted the wrong one...here is the function which calls list when a category is clicked and in this, I want to show paginate.

public function show(Category $category)
    {
        $categories = Category::all();
        $links = $category->links();
        return view('links.category', compact('links', 'categories'));
    }
Activity icon

Started a new Conversation List With Paginate

I have a view with the category on the left and the list on left. But no pagination.

How to display links with paginating?

public function show(Link $link)
    {
        $link->load('category');
        return view('links.single', compact('link'));
    }
Oct
01
1 month ago
Activity icon

Awarded Best Reply on 404 On Updating User From Admin Panel

Finally, I got it. I am using the getRouteKeyName in the user model to hide the id.

When I changed $user->id to $user->name I got the result.

Like this in the form: <form action="{{route('admemup', $user->name)}}" method="POST">

Activity icon

Replied to 404 On Updating User From Admin Panel

Finally, I got it. I am using the getRouteKeyName in the user model to hide the id.

When I changed $user->id to $user->name I got the result.

Like this in the form: <form action="{{route('admemup', $user->name)}}" method="POST">

Activity icon

Started a new Conversation How To Assign And Get Null Data

I am working on the user list and assigning them normal users or admin. For this, I am just using the data entry for user type...I am not working on policy right now.

So, I have two questions about this.

  • How to assign the user a null value from the drop-down selector
  • How to list users who have a null value

Controller: for listing the users having null value

public function memlist()
    {
        $users = User::where('type', '...')->paginate(10);
        return view('admin.users', compact('users'));
    }

View: for editing the user type. Here I do not want to add any entry for NULL

<select name="type" class="custom-select">
                              <option selected="">Select</option>
                              
                                <option value="Admin" {{ $user->type === 'Admin' ? ' selected' : '' }}>Yes</option>
                                <option value="NULL" {{ $user->type === 'NULL' ? ' selected' : '' }}>No</option>
                              
                            </select>
Sep
30
1 month ago
Activity icon

Started a new Conversation Finally Going To Try Laravel App Online

I am almost done, so once again I want to try the laravel project online.

I am trying to move laravel project to a ZIP folder where I see "File not found or no read permission".

I thought it is windows side mistakes I have done or any other files may be left open. But nothing like that, even I have tried to remove the zip folder inside vendor folder and unchecked the read-only checkbox for laravel files.

Still no success. FInally I checked the other laravel project and did the same and it has done. Then I compared the files inside it and saw a few files are there in my completed project.

So now I came to the final conclusion. Which files are required. I see node_modul folder and some other files are extra.

Would you please list the files and folders I have to move on zip folder so I can use the project online. Or if I sell the project what files and folders I should give them...?

Activity icon

Started a new Conversation What Is Swiftmailer And Textfile Inside It

My question is simple yet very frustrated. "What is swiftmailer and a zip folder inside named textfile..."?

I was trying to move the project in zip for online setup. This is because I am seeing some error like 404 on updating the user data from admin side and "stream_socket_enable_crypto..."

I think I should check this using an online server, possibly I have not installed some xampp mailing requirement of something on php...

So I tried to create zip where I see "file not found or no read permission". And this took me another two days to find the real problem where a blog answered it, to look zip folder inside my project.

And yes there is a zip folder inside swiftmailer. I see a zip folder "textfile". So, what should I do? Remove it, or extract it and keep that? Also please answer why there is a zip folder deep inside the vendor folder?

Sep
29
2 months ago
Activity icon

Replied to 404 On Updating User From Admin Panel

If the user controller uses the Auth middleware, how can an admin edit the user's data...?

Because here I see the somehow the user model is not found. Possibly this is the reason for the 404 error.

If I want to let admin edit the user data, how should I do it?

Activity icon

Replied to 404 On Updating User From Admin Panel

@michaloravec The same error...

Even return redirect()->back(); shows the same 404 error.

Activity icon

Replied to 404 On Updating User From Admin Panel

@sergiu17 The same error appears... 404 error