webfuelcode

webfuelcode

Member Since 1 Year Ago

Experience Points
7,640
Total
Experience

2,360 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
56
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
7,640 XP
Sep
22
21 hours ago
Activity icon

Replied to Failed To Open Stream: No Such File Or Directory

@laracoft

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Application Name
    |--------------------------------------------------------------------------
    |
    | This value is the name of your application. This value is used when the
    | framework needs to place the application's name in a notification or
    | any other location as required by the application or its packages.
    |
    */

    'name' => env('APP_NAME', 'Laravel'),

    /*
    |--------------------------------------------------------------------------
    | Application Environment
    |--------------------------------------------------------------------------
    |
    | This value determines the "environment" your application is currently
    | running in. This may determine how you prefer to configure various
    | services the application utilizes. Set this in your ".env" file.
    |
    */

    'env' => env('APP_ENV', 'production'),

    /*
    |--------------------------------------------------------------------------
    | Application Debug Mode
    |--------------------------------------------------------------------------
    |
    | When your application is in debug mode, detailed error messages with
    | stack traces will be shown on every error that occurs within your
    | application. If disabled, a simple generic error page is shown.
    |
    */

    'debug' => env('APP_DEBUG', false),

    /*
    |--------------------------------------------------------------------------
    | Application URL
    |--------------------------------------------------------------------------
    |
    | This URL is used by the console to properly generate URLs when using
    | the Artisan command line tool. You should set this to the root of
    | your application so that it is used when running Artisan tasks.
    |
    */

    'url' => env('APP_URL', 'http://localhost'),

    'asset_url' => env('ASSET_URL', null),

    /*
    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    */

    'timezone' => 'UTC',

    /*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */

    'locale' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Application Fallback Locale
    |--------------------------------------------------------------------------
    |
    | The fallback locale determines the locale to use when the current one
    | is not available. You may change the value to correspond to any of
    | the language folders that are provided through your application.
    |
    */

    'fallback_locale' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Faker Locale
    |--------------------------------------------------------------------------
    |
    | This locale will be used by the Faker PHP library when generating fake
    | data for your database seeds. For example, this will be used to get
    | localized telephone numbers, street address information and more.
    |
    */

    'faker_locale' => 'en_US',

    /*
    |--------------------------------------------------------------------------
    | Encryption Key
    |--------------------------------------------------------------------------
    |
    | This key is used by the Illuminate encrypter service and should be set
    | to a random, 32 character string, otherwise these encrypted strings
    | will not be safe. Please do this before deploying an application!
    |
    */

    'key' => env('APP_KEY'),

    'cipher' => 'AES-256-CBC',

    /*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */

    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notifications\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,

        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

    ],

    /*
    |--------------------------------------------------------------------------
    | Class Aliases
    |--------------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don't hinder performance.
    |
    */

    'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Arr' => Illuminate\Support\Arr::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,
        'Blade' => Illuminate\Support\Facades\Blade::class,
        'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
        'Bus' => Illuminate\Support\Facades\Bus::class,
        'Cache' => Illuminate\Support\Facades\Cache::class,
        'Config' => Illuminate\Support\Facades\Config::class,
        'Cookie' => Illuminate\Support\Facades\Cookie::class,
        'Crypt' => Illuminate\Support\Facades\Crypt::class,
        'DB' => Illuminate\Support\Facades\DB::class,
        'Eloquent' => Illuminate\Database\Eloquent\Model::class,
        'Event' => Illuminate\Support\Facades\Event::class,
        'File' => Illuminate\Support\Facades\File::class,
        'Gate' => Illuminate\Support\Facades\Gate::class,
        'Hash' => Illuminate\Support\Facades\Hash::class,
        'Http' => Illuminate\Support\Facades\Http::class,
        'Lang' => Illuminate\Support\Facades\Lang::class,
        'Log' => Illuminate\Support\Facades\Log::class,
        'Mail' => Illuminate\Support\Facades\Mail::class,
        'Notification' => Illuminate\Support\Facades\Notification::class,
        'Password' => Illuminate\Support\Facades\Password::class,
        'Queue' => Illuminate\Support\Facades\Queue::class,
        'Redirect' => Illuminate\Support\Facades\Redirect::class,
        'Redis' => Illuminate\Support\Facades\Redis::class,
        'Request' => Illuminate\Support\Facades\Request::class,
        'Response' => Illuminate\Support\Facades\Response::class,
        'Route' => Illuminate\Support\Facades\Route::class,
        'Schema' => Illuminate\Support\Facades\Schema::class,
        'Session' => Illuminate\Support\Facades\Session::class,
        'Storage' => Illuminate\Support\Facades\Storage::class,
        'Str' => Illuminate\Support\Str::class,
        'URL' => Illuminate\Support\Facades\URL::class,
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View' => Illuminate\Support\Facades\View::class,

    ],

];

Activity icon

Replied to Failed To Open Stream: No Such File Or Directory

@laracoft @automica After running this composer dump-autoload I have now...

In Application.php line 690: Class 'Illuminate\Foundation\Providers\ComposerServiceProvider' not found

Activity icon

Started a new Conversation Failed To Open Stream: No Such File Or Directory

include<C:...................laravel/framework/src/illuminate/Foundation/Providers/CompoerServiceProvider.php: failed to open stream: no such file or directory at C:..........vendor\composer\ClassLoader.php:444 prevents access to $this/self from included files. .................

I am not able to create model, each time I use the php artisan make:model it comes with the error.

Previously I tried to create my own provider and got no success on it so I removed the file. No what should I do to fix it?

Activity icon

Started a new Conversation Eloquent Where() For Two Column Match

Trying to create a search result for posts that will search on the title and description column.

I can make it happen like this for one:

public function search(Request $request)
    {
        $this->validate($request, [
            'q' => 'required',
        ]);
        $links = Link::where('title', 'like', '%' . $request->q . '%')->get();
    
        return view('links.search', compact('links'));
    }

How to set it for two different columns in one search...like $links = Link::where('title', 'like', '%' . $request->q . '%')->get(); and $links = Link::where('description', 'like', '%' . $request->q . '%')->get();

Sep
20
2 days ago
Activity icon

Started a new Conversation Trying To Set Data Entry Nullable Or Default Entry

I am trying to update the data but it shows error

Integrity constraint violation: 1048 Column 'short' cannot be null

I have done seeder for default value so the site owner will get a message if it is not set. But I also want to let the table column NULL if they do not want to fill data.

Can I set it?

Table schema:

....
$table->string('short')->nullable();
....

And the default entry is:

DB::table('setting')->insert('short'=>'A short description will go here',)
Sep
18
4 days ago
Activity icon

Started a new Conversation Meaning And Using Of First()

Trying to understand eloquent where I am using one entry only and let the site admin update it.

Meaning and difference between $settings = Setting::first(); and $settings = Setting::all()->first();

Are both the same?

Activity icon

Replied to Whats Wrong Here On AppServiceProvider For Passing Data To Welcome Page

@sergiu17

Welcome.blade.php file is here:

@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="card w-100 bg-primary text-light p-5">
            <p>{{$admin->sitemsg}}</p>
        </div>
        <div class="row justify-content-center">
            @forelse ($links as $link)
                <div class="col-md-3 my-2">
                    <div class="card text-white bg-primary">
                        <h5 class="card-header">
                            {{ $link->title }}
                        </h5>
                        <div class="card-body">
                            <p class="card-text">
                                {{ $link->description }}
                            </p>
                            <div class="card-text">
                                <a class="float-right btn btn-light btn-sm" href="{{ route('link.show', $link->id) }}">See this</a>
                            </div>
                        </div>
                        
                    </div>
                </div>
                @empty
                No sites are in the record.
                
            @endforelse
        </div>

        <div>
            <p class="text-center">Find sites via suitable categories available below.</p>
        </div>
        <div class="row">
            @forelse ($categories as $category)
                <div class="col-md-3">
                    <div class="card bg-dark text-white p-4 text-center">
                        {{ $category->name }} ({{ $category->links()->count() }})                        
                    </div>
                </div>
            @empty
                No catrgories are in the record.
            @endforelse
        </div>        
    </div>
@endsection
Activity icon

Started a new Conversation Whats Wrong Here On AppServiceProvider For Passing Data To Welcome Page

I just tried AppServiceProvider for admin data to display on all pages. Working fine except the welcome page (homepage).

It says

Undefined variable: admin (View: ...........\welcome.blade.php)

AppServiceProvider is here:

    public function boot()
    {

        view::composer('layouts.app', function($view){
            $view->with('admin', AdminSet::all()->first());
        });
    }

And welcome view has {{$admin->description}}

But all other pages work fine. Well, I am using the layout page for this...

Activity icon

Started a new Conversation What Is Good Practice To Avoid Repeating Class

Suppose I have models - post, image, category, link ... and admin, so controllers repeatedly.

What if I need admin class to call in each controller and in the function too.

In this case, I have to add a line on the top like use App\Admin;

What about in the functions where I have multiple of it in the same controller and the same on all other controllers?

Like

public function index()
    {
        $categories = Category::all();
        $links = Link::paginate(8);
        $admin = Admin::first();
}

public function show()
    {
        $posts = Category::all();
	//others goes here
        $admin = Admin::first();
}

public function home()
    {
        $articles = Article::all();
	//others goes here
        $admin = Admin::first();
}

If I have to repeat $admin = Admin::first(); many times, what is the good practice or I have to keep it doing in the functions...

Sep
17
5 days ago
Activity icon

Replied to Trying To Setup Default Data Entry On Migration

@laracoft @silencebringer

I am trying to allow the site owner to set the site title, description, social page links...through a page, just to make it easy for the owner. As the site title is fixed for every owner so they will not go to create another one.

So here is controller for view:

public function settings()
    {
        $settings = AdminSet::all();
        return view('admin.settings', compact('settings'));
    }

I have tried this for table:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminSetsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_sets', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title')->default('SiteTITLE');
            $table->string('description')->default('A simple site listing directory.');
            $table->string('keywords')->nullable();
            $table->string('about')->default('Easy site listings');
            $table->string('sitemsg')->default('Edit the demo text for visitors.');
            $table->string('rtitle')->default('Contact Us');
            $table->string('rmsg')->default('[email protected]');
            $table->string('captcha')->nullable();
            $table->string('leaderads')->nullable();
            $table->string('sideads')->nullable();
            $table->string('facebook')->nullable();
            $table->string('twitter')->nullable();
            $table->string('linkedin')->nullable();
            $table->string('blog')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_sets');
    }
}
  • So how to call the data if available. Like social icons and site message on home page...
  • Before it there must have something to get from DB.
  • I am trying to make some default entry on admin site. Is it okay to use seeder...
Activity icon

Started a new Conversation Trying To Setup Default Data Entry On Migration

I am working on a simple site where I want to give privilege to the site owner to set up some basic details about the site. Like site description, keywords, homepage title and a short description and others...

In this idea, I am facing some problems: where this entry will have no new creation and only the editing side. So I am trying to put the default value unless the site owner edits it. And this same data will later be edited by the owner.

So I am not able to find the way to put default data.

  • One entry already (default)
  • The same data will be edited.

While making ->default() I am facing property not exist...using form value {{old('title'), $settings->title}}

Activity icon

Replied to Getting The Category And Posts Inside It

@automica I tried this and I think this is to display one single category and its listings in a page.

Where my purpose is to display 3-4 category (or a few chosen) with limited listings. Something like this... category

Sep
14
1 week ago
Activity icon

Started a new Conversation Getting The Category And Posts Inside It

Working on a directory where I want to display category and few numbers of posts inside that category.

Category and link facades are added to the controller. It is working fine to display list of categories and a list of links on the homepage.

My main concern is to use the relationship to get the category and a few lists from that category.

Actually it is a design concern, where I want the home page to show 3-4 categories and few links. It would a table or bootstrap card where the category name will appear on top and the list.

I am not sure to use the relation. Nothing much complicated I have just used a category and links relationship.

Sep
11
1 week ago
Activity icon

Replied to Trying To Show Category Name On The Post

@sinnbeck This is Category model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

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

    public function links()
    {
        return $this->hasMany(Link::class, 'cat_id');
    }
}

This is Link model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

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

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

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

And here the single page where I want to get the post detail with it's category

@extends('layouts.app')

@section('content')
    <div class="container">
        {{--Site messages--}}
        @include('partials.msg')
        {{--Site messages ends--}}
        <div class="clearfix">
            <a href="{{ route('link.index') }}" class="btn btn-warning float-left">List</a>
            <a href="{{ route('link.create') }}" class="btn btn-primary float-right">Add</a>
        </div>
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card border-0">
                    <h4 class="card-header">
                        {{ $link->title }}
                    </h4>
                    <div class="card-body">
                        <p class="card-text">
                            {{ $link->description }}
                        </p>
                        
                        <div class="card-text">
                            {{ $link->url }}
                        </div>
                        <div class="card-link">
                            <strong>In category:</strong> {{ $link->category->name ?? 'Uncategorized' }}
                        </div>
                        @auth
                        @if (auth()->user()->id == $link->user_id)
                        <div class="card-link float-right">
                
                            <div class="actions form-inline">
                                <a href="{{route('link.edit', $link->id)}}" class="btn btn-success btn-sm badge form-group m-1">Edit</a>

                                <button type="submit" class="btn btn-danger badge m-1" data-toggle="modal" data-target="#delete{{$link->id}}">Delete</button>
                                @include('partials.delete_post')
                                
                            </div>
                            
                        </div>
                    @endif
                        @endauth
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
Activity icon

Started a new Conversation Trying To Show Category Name On The Post

The error appears

Trying to get property 'name' of non-object

Controller for single page view:

public function show(Link $link)
    {
        $link->load('category');
        return view('links.single', compact('link'));
    }

For view page:

{{ $link->category->name }}
Sep
09
1 week ago
Activity icon

Replied to Installing The Older Version Of Laravel

@sinnbeck can get laravel with the auth setup using a one-line command for the older version.

Becasue composer require laravel/ui and then php artisan ui vue --auth takes a lot of time.

Activity icon

Started a new Conversation Installing The Older Version Of Laravel

I just used laravel new BLOG --auth to create a new project. All basic setup and new registration showed me an error:

Class 'App\User' not found ...Controllers\Auth\RegisterController.php:67

I am just learning laravel and any version will work for me. So I do not want to stuck in these errors better to focus on the project.

Please tell me how to get the older version with auth set up so I can do it with one command.

Laravel 7 will be fine...

Sep
08
2 weeks ago
Activity icon

Started a new Conversation How To Update The Category Name

I am trying to update the category name and I found something like this...

public function update(Request $request, Category $category)
    {
        $this->validate($request,[
            'name' => 'required|min:3|max:50'
        ]);

        $category->update($request->all());
        return redirect()->route('cats.index', $category->id)->withMessage('Edited successfuly!');
    }

Which is, I find wrong in my case. I found this on a tutorial and tried to make it for my project updating the category name... I do not understand $category->update($request->all());

  • Can you please explain what $category->update($request->all()); means?
  • And what shout I use in place of this to update the category name?

Currently, I do not see the changes. Please make it work for me.

Activity icon

Replied to What Is The Good Practice Of Using Route?

@tisuchi I see this Route::resource('photos', PhotoController::class); where I have learnt something Route::resource('photos', PhotoController);

Working both the same ...?

Cause I am seeing 404 using resource but a single point to the method works fine.

Activity icon

Started a new Conversation What Is The Good Practice Of Using Route?

I am working on a simple project to learn laravel. Currently, I am facing a 404 error in some ways, like edit, delete and showing category posts.

Some of these are good when I use route individually.

My question is why do we use Route::resource('categories', 'CategoryController'); and why single like this Route::get('categories', '[email protected]');

I mean when to use resource and when get, post and ...

Sep
06
2 weeks ago
Activity icon

Replied to How To Get The Post List Via Category Link

@snapey

  • Yes, route /categories shows the list of categories.

  • This is what I am trying to do. I want to make the category clickable links to the page of related posts. But here I see 404 error.

The CategoryController index is:

public function index()
    {
        $categories = Category::all();
        $categories = Category::paginate(10);
        return view('admin.create_category', compact('categories'));
    }

And the view page I am using is:

@extends('layouts.app')

@section('content')
    <div class="container">
        @include('partials.msg')
        @include('partials.errormsg')
        <div class="row">
            <div class="col-md-9">
                <h2>Categories</h2>
                <table class="table table-hover">
                    <thead class="bg-warning">
                        <tr>
                            <th>#</th>
                            <th>Name</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($categories as $category)
                        <tr>
                            <td>{{ $category->id }}</td>
                            <td><a href="{{ route('categories.show', $category->id) }}">{{ $category->name }}</a></td>
                            <td>
                                <!-- Edit button -->
                                <div class="float-left">
                                    <button type="button" class="btn btn-success" data-toggle="modal" data-target="#modal{{$category->id}}">
                                        Edit
                                    </button>
                                </div>
                                @include('admin.partials.edit_category')
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>

            </div>
            
            <div class="col-md-3">
                <form action="{{route('categories.store')}}" method="POST" class="card bg-danger text-white p-2">
                    @csrf
                    <div class="form-group">
                      <label for="name">Category name</label>
                      <input type="text" name="name" class="form-control" placeholder="Enter new category">
                    </div>
                    <button type="submit" class="btn btn-outline-light btn-lg btn-block">Submit</button>
                  </form>

                  <div class="card border-info my-2">
                    <div class="card-header">
                        Site operation
                    </div>
                    <div class="card-body">
                        
                        <div class="card-link">
                          <a class="btn btn-outline-warning btn-lg btn-block" href="{{ route('link.index') }}">See the list</a>
                          <a class="btn btn-outline-info btn-lg btn-block" href="{{ route('link.create') }}">Add new post</a>
                        </div>
                    </div>
                  </div>
    
            </div>
        </div>
    </div>
@endsection
Activity icon

Replied to How To Get The Post List Via Category Link

@automica thanks for the post count, it is fine.

And here I did not cleary about the pages. Posting again about the same...actually the function above is different and the loop coming from a different function which is index. So making things clear again here...

I am using resource in route:

Route::resource('categories', 'CategoryController', ['except' => ['create']]);

I have LinkController here:

public function index()
    {
        $links = Link::paginate(5);
        $categories = Category::all();
        return view('list', compact('links', 'categories'));
    }

And CategoryController is this:

public function show(Category $category)
    {
        //$category = $category->links;
        return view('category', compact('category'));
    }

And list.blade.php page where the foreach loop is used as in the previous post. Now I have changed it to this one:

<ul class="list-group">
                        
                        @foreach ($categories as $category)
                            
                                <a class="list-group-item d-flex justify-content-between align-item-center" href="{{route('categories.show', $category->id)}}">{{$category->name}} <span class="badge-info badge-pill">{{$category->links()->count()}}</span></a>
                            
                        @endforeach
                    </ul>

I want to set the link in this list.blade.php file which will show the post according to category. So I have created category page and it is added on CategoryCotroller. But this category page shows 404 error...whats is the mistake there...

I have not added anything on category page, just a title and trying to get the category name.

Activity icon

Replied to Property Does Not Exist Error On Single Page View

@snapey Thanks for the help its working... Well I am using this:

public function show(Link $link)
    {
        $categories = Link::where('category_id')->get();
        return view('single', compact('link', 'categories'));
    }

Can you tell me the difference between $link->load('category'); and $categories = Link::where('category_id')->get(); and benefits...?

Sep
05
2 weeks ago
Activity icon

Started a new Conversation How To Get The Post List Via Category Link

Working on the category where the link will open the posts list. I am also looking to count the number of posts per category.

Controller:

public function show(Category $category)
    {
        return view('category', compact('category'));
    }

View page:

@foreach ($categories as $category)
                            <li class="list-group-item">
                                <a href="{{route('categories.show', $category->id)}}">{{$category->name}}</a>
                            </li>
                        @endforeach

The error appears 404 erroe.

Activity icon

Replied to Property Does Not Exist Error On Single Page View

@snapey removing link shows another error on category. This is what want to show on a single page.

Using this:

public function show(Link $link)
    {
        return view('single', compact('link'));
    }

Show another error is:

Trying to get property 'name' of non-object

Which is about {{$link->category->name}}

So how to show the category on a single post page...

Sep
04
2 weeks ago
Activity icon

Started a new Conversation Property Does Not Exist Error On Single Page View

After adding the category, I see this error on single view page. Before category it was working fine.

Error see:

Property [title] does not exist on this collection instance.

Also category id does not save on link table

Single view page is here:

@extends('layouts.app')

@section('content')
    <div class="container">
        {{--Site messages--}}
        @include('partials.msg')
        {{--Site messages ends--}}
        <div class="clearfix">
            <a href="{{ route('link.index') }}" class="btn btn-warning float-left">List</a>
            <a href="{{ route('link.create') }}" class="btn btn-primary float-right">Add</a>
        </div>
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card border-0">
                    <h4 class="card-header">
                        {{ $link->title }}
                    </h4>
                    <div class="card-body">
                        <p class="card-text">
                            {{ $link->description }}
                        </p>
                        
                        <div class="card-text">
                            {{ $link->url }}
                        </div>
                        <div class="card-link">
                            {{-- $link->category->name --}}
                        </div>
                        @auth
                        @if (auth()->user()->id == $link->user_id)
                        <div class="card-link float-right">
                
                            <div class="actions form-inline">
                                <a href="{{route('link.edit', $link->id)}}" class="btn btn-info btn-sm badge form-group m-1">Edit</a>

                                <form action="{{route('link.destroy', $link->id)}}" method="POST" class="form-group">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-danger badge m-1">Delete</button>
                                </form>
                            </div>
                            
                        </div>
                    @endif
                        @endauth
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

Controller is here for store and show function:

public function store(Request $request)
    {
        $validated = $this->validate($request,[
            'title'=>'required|min:5',
            'url'=>'required',
            'category_id'=>'required',
            'description'=>'required|min:10'
        ]);

        //store
        $link = auth()->user()->links()->create($validated);
        

        //redirect
        return redirect()->route('link.show', ['link' => $link->id])->withMessage('Site added successfuly');
    }

public function show(link $link)
    {
        $link = Link::find($link);
        return view('single', compact('link'));
    }

Submit form is here:

@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="clearfix">
            <a href="{{ route('link.index') }}" class="btn btn-warning float-left">List</a>
            
            <a href="{{ route('link.create') }}" class="btn btn-primary float-right">Add</a>
        </div>
        <div class="row justify-content-center">
            <div class="col-md-8">
                <form action="{{route('link.store')}}" method="POST">
                  @csrf
                  <div class="form-group">
                    <label for="title">Site title</label>
                    <input type="text" name="title" class="form-control" placeholder="Enter site title">
                  </div>
                  <div class="form-group">
                    <label for="url">Site URL</label>
                    <input type="text" name="url" class="form-control" placeholder="Enter site URL">
                  </div>
                  <div class="form-group">
                    <label for="category_id">Category</label>
                    <select name="category_id" class="custom-select">
                      <option selected="">Select a category</option>
                      @foreach ($categories as $category)
                        <option value="{{ $category->id }}">{{ $category->name }}</option>
                      @endforeach                      
                    </select>
                  </div>
                  <div class="form-group">
                    <label for="description">Site description</label>
                    <textarea name="description" class="form-control" cols="30" rows="10" placeholder="Enter site description"></textarea>
                  </div>
                  <button type="submit" class="btn btn-primary btn-block">Submit</button>
                </form>
            </div>
        </div>
    </div>
@endsection
Sep
03
2 weeks ago
Activity icon

Started a new Conversation How To Make It Visible For Non Members

A single post page shows error

Trying to get property 'id' of non-object

The error shows the line where if the statement is placed which @if (auth()->user()->id == $link->user_id) in the below file.

@extends('layouts.app')

@section('content')
    <div class="container">
        {{--Site messages--}}
        @include('partials.msg')
        {{--Site messages ends--}}
        <div class="clearfix">
            <a href="{{ route('link.index') }}" class="btn btn-warning float-left">List</a>
            <a href="{{ route('link.create') }}" class="btn btn-primary float-right">Add</a>
        </div>
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card border-0">
                    <h4 class="card-header">
                        {{ $link->title }}
                    </h4>
                    <div class="card-body">
                        <p class="card-text">
                            {{ $link->description }}
                        </p>
                        
                        <div class="card-text">
                            {{ $link->url }}
                        </div>
                        @if (auth()->user()->id == $link->user_id)
                            <div class="card-link float-right">
                    
                                <div class="actions form-inline">
                                    <a href="{{route('link.edit', $link->id)}}" class="btn btn-info btn-sm badge form-group m-1">Edit</a>

                                    <form action="{{route('link.destroy', $link->id)}}" method="POST" class="form-group">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-danger badge m-1">Delete</button>
                                    </form>
                                </div>
                                
                            </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

Controller file is here

function __construct()
    {
        return $this->middleware('auth')->except('index', 'show');
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $links = Link::paginate(5);
        return view('list', compact('links'));
    }

	public function show(link $link)
    {
        return view('single', compact('link'));
    }
Sep
02
2 weeks ago
Activity icon

Replied to How To Use @foreach On Index Page

Thanks, I got it.

Actually I was not clear about transferring the variable value on the homepage where you are not sending value through a link.

I knew it can be done using a controller but again it will have to make a link and transfer it.

Finally, I got this to make it happen. A small function on the route file.

Route::get('/', function () {
    $links = App\Link::paginate(8);
    return view('welcome', compact('links'));
});

And then I can use the @foreach loop on the homepage.

The error was "Undefined variable" for that particular variable I have used in foreach.

Activity icon

Started a new Conversation How To Use @foreach On Index Page

Good practice of using @foreach on the homepage.

I am trying to design two pages with different styles with posts loop from the database. One page is inside the member's area which is linked in the dashboard, so members can see it. Also, non-members can visit it if they have the link.

But I want to show the same list with a different style on the homepage. So how to use the @foreach and pass the value for the variable?

Basically, the question is about passing error. "Undefined variable:"

Aug
31
3 weeks ago
Activity icon

Replied to Error On Adding A Category Name

@michaloravec

After doing all this, there is another error...

BadMethodCallException Call to undefined method App\Category::makeSlug()

Aug
30
3 weeks ago
Activity icon

Started a new Conversation Error On Adding A Category Name

Trying to add a category name for a link directory project. But the new category name shows error.

I see this error

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'RLINK '^internet(-[0-9])?$' order by id desc limit 1' at line 1 (SQL: select slug from categories where slug RLINK '^internet(-[0-9])?$' order by id desc limit 1)

Controller side is here

public function store(Request $request)
    {
        $request->validate([
            'categoryname' => 'required|max:225'
        ]);

        $category = new Category();
        $category->categoryname = $request['categoryname'];
        $category->slug = str_slug($request['categoryname']);

        $latestSlug = Category::whereRaw("slug RLINK '^{$category->slug}(-[0-9]*)?$'")
        ->latest('id')
        ->value('slug');
            if ($latestSlug) {
                $pieces = explode('-', $latestSlug);
                $number = intval(end($pieces));
                $category->slug .= '-' . ($number + 1);
            }
            $category->save();
            return redirect('home')->withMessage('New category added');
    }
Aug
20
1 month ago
Activity icon

Started a new Conversation Trying To Show Default Avatar Using If-else

I am working on this to show user's avatar. If not set it will show the default.

The below condition shows the default avatar all the time and does not change when new uploaded. What's wrong here...?

@if (empty(auth()->user->avatar))
         <img class="dp" src="/uploads/avatar/machine/default.png">
@else
          <img class="dp" src="/uploads/avatar/{{auth()->user()->avatar}}">
@endif
Aug
17
1 month ago
Activity icon

Started a new Conversation How To Delete Avatar When New Uploaded?

This is the controller for the avatar upload page. Please guide me to delete the older one when the new avatar is uploaded.

Avatar file folder in the public folder - public/uploads/avatar...

public function update_avatar(Request $request){
        if($request->hasFile('avatar')){
            $filename = time() . '.' . $request->avatar->getClientOriginalExtension();
            if(auth()->user()->avatar){
                File::delete('/uploads/avatar/' . auth()->user()->avatar);
            }
            $request->avatar->storeAs('avatar', $filename, 'my_files');

            $user = Auth::user();
            $user->avatar = $filename;
            $user->save();
        }
        return redirect()->back();
    }
Aug
12
1 month ago
Activity icon

Started a new Conversation How To Redirect To The Post Page After Creation

Currently, the user can create a post and redirect it to back (same page) after the successful creation of the thread post.

Here I want to redirect the user to the post which he just created. If the error on the post creation, he must stay on the same page which will show the error message.

If everything is correct then the redirection will work.

Below is thread controller, store function:

public function store(Request $request)
    {
        //validate
        $this->validate($request,[
            'subject'=>'required|min:10',
            'type'=>'required',
            'thread'=>'required|min:20'
        ]);

        //store
        auth()->user()->threads()->create($request->all());
        

        //redirect
        return back()->withMessage('Thread created successfuly');
    }

Activity icon

Replied to How To Add The Pagination On Index

@snapey @neeraj1005

Here is the controller:

public function index()
    {
        $threads = Thread::orderBy('created_at', 'desc')->get();
        $threads = Thread::paginate(5);
        return view( 'thread.index', compact('threads') );
    }

@apexleo the thread model is here and I am not how to incert the paginate:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Thread extends Model
{
    use CommentableTrait;
    protected $fillable=['subject', 'type', 'thread', 'user_id'];

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
Aug
11
1 month ago
Activity icon

Replied to How To Add The Pagination On Index

@snapey I have created a page for thread list and managed it to appear 5 posts at a time and display pagination below it. This single page works fine with pagination.

The same page I have included on the index page with @include

My question is, why the pagination does not appear there? or How to make a thread list with pagination on the index page?

I think @include display the whole pages pagination must appear there? I think.

Activity icon

Started a new Conversation How To Add The Pagination On Index

Using single thread list on index page with @include. How to use pagination on index as single page is working good.

Index page is here

@extends('layouts.front')

@section('heading')
    <a href="{{route('thread.create')}}" class="btn btn-success float-right">Create Thread</a><br>
@endsection

@section('content')

@include('layouts.partials.msg')

<h2>Threads</h2>

@include('thread.partials.thread-list')

@endsection

Single thread list is here thread.partials.thread-list

<div class="">
    @forelse ($threads as $thread)
        <div class="card my-2">
            <div class="card-body">
                <a href="{{route('thread.show', $thread->id)}}">
                    <h4 class="card-title">{{ $thread->subject }}</h4>
                </a>
                    <p class="card-text">{{ str_limit($thread->thread,100) }}</p>
                    <p class="card-link">Posted by: <a href="{{route('user_profile',$thread->user->name)}}">{{$thread->user->name}}</a> {{$thread->created_at->diffForHumans()}}</p>
                
            </div>
        </div>
        
    @empty
            <h5>No threads there</h5>
        
    @endforelse

    {{ $threads->links() }}
</div>
Aug
08
1 month ago
Activity icon

Replied to Undefined Index: User

@ajithlal I tried others too but the error is the same ''undefined index: user`` Is there something I have to use a class on the controller...

And one more thing...I only see this error on using $notifications = auth()->user()->notifications; on controller but good with $notifications = auth()->user()->unreadnotifications;

Activity icon

Replied to Is This The Correct Way To Display Unread Notification?

@bobbybouwmann

I am trying to build a separate page for all read and unread notifications to be shown. And give the user to delete it from there.

But I am facing error undefined index: user on using controller side$notifications = auth()->user->notifications; but it is fine with $notifications = auth()->user->unreadnotifications;

Below is where I see undefined index: user thread subject and id works fine by using data['thread']['subject'] or id there but does not work on data['user']['name']

View blade file is here:

@foreach($notifications as $notifications)
                {{ $notifications->data['user']['name'] }}
                commented on
                {{ $notifications->data['thread']['subject'] }}
                 - {{ $notifications->data['user']['created_at'] }}<br>
@endforeach

And the controller is:

$notifications = auth()->user()->notifications;
        return view('profile.notifications', ['notifications' => $notifications]);
Activity icon

Replied to Undefined Index: User

@tisuchi

dd($notifications) shows attributes array like this:

"data" => "{"thread":{"id":3,"subject":"The third thread via form","thread":"This is the third thread via the form. It looks fine. Let's move forward to make it more appealing.","type":"question","created_at":"2020-07-08T14:12:58.000000Z","updated_at":"2020-07-08T14:12:58.000000Z","user_id":1,"user":{"id":1,"name":"Rick","email":"[email protected]","email_verified_at":null,"created_at":"2020-07-07T14:07:50.000000Z","updated_at":"2020-08-06T13:39:40.000000Z"}},"user":{"id":2,"name":"Jack","email":"[email protected]","email_verified_at":null,"created_at":"2020-07-18T14:41:56.000000Z","updated_at":"2020-08-06T06:29:42.000000Z"}}"

@ajithlal using dd($notifications) on controller and on view page {{$notification->data['thread']['subject']}} is fine but shows error on using {{$notification->data['thread']['user']}}

And the error is:

htmlspecialchars() expects parameter 1 to be string, array given (View: C:\xampp\htdocs\machine\resources\views\profile\notifications.blade.php)

Activity icon

Replied to Undefined Index: User

@tisuchi

@extends('layouts.front')

@section('content')
    <div class="row">
        <div class="col-md-12">
            <h4>Unread Notifications</h4>

            <li>
            @foreach ($notifications as $notification)
                {{ $notification->data['user']['name'] }}
                commented on
                {{ $notification->data['thread']['subject'] }}
                 - {{ $notification->data['user']['created_at'] }}<br>
            @endforeach
            </li>
        </div>
    </div>
@endsection
Activity icon

Started a new Conversation Undefined Index: User

Undefined index: user (View: C:\xampp\htdocs\machine\resources\views\profile\notifications.blade.php)

Why do I see the undefined index error?

Controller:

public function show()
{
return view('profile.notifications', ['notifications' => auth()->user()->notifications]);
}

View:

<li>
            @foreach ($notifications as $notification)
                {{ $notification->data['user']['name'] }}
                commented on
                {{ $notification->data['thread']['subject'] }}
                 - {{ $notification->data['user']['created_at'] }}<br>
            @endforeach
</li>

Screenshot is here. Image link is here: "https://i.ibb.co/9rK5xbg/lara-notice.png

Activity icon

Replied to Laravel Email Contact Form 7

Web hosts provide it or use Gmail for the same.

Activity icon

Started a new Conversation Is This The Correct Way To Display Unread Notification?

I am little confused if it is correct or not. As I am showing a page for all unread notification and not sure about the auth.

Please look and make it correct if wrong. Or you know the correct way to do this.

Controller side is here:

$notifications = auth()->user()->unReadNotifications;
        foreach($notifications as $notification)
        {
            //dd ($notification);
            return view('profile.notifications', compact('notification'));
        }

View side is here:

            @foreach(Auth::user()->unReadNotifications as $notifications)
                {{ $notifications->data['user']['name'] }}
                commented on
                {{ $notifications->data['thread']['subject'] }}
                 - {{ $notifications->data['user']['created_at'] }}<br>
            @endforeach

The actual part where I am confused is, the auth. Do I need to use auth()->user() on both of the pages...

Activity icon

Started a new Conversation How To Use DiffForHumans In Notification?

I am trying to use notification time in an easy form to read. Like diffForHumans...

How to make it here:

{{ $notifications->data['user']['created_at'] }}
Aug
06
1 month ago
Activity icon

Started a new Conversation Redirect Other Logged-in Users To Their Own Profile Edit

I am working on the profile edit page and trying to restrict other members to view page. And when they try to visit other's profile edit page, they will redirect to their own profile edit page.

This time I am facing, anyone can visit the page and even edit any other profile page.

Here is the route which shows users editing page:

Route::get('user/{user}', '[email protected]');

Profile controller where I am trying to redirect:

public function edit(User $user)
    {
        $user = User::find($user->id);
        return view( 'profile.editprofile', compact('user') );
    }

So, the edit page address will look like this URL localhost/user/Rick which passes the user data on that page. If the URL is edited with the different user's name it shows the other member's data to edit and even it does that. Means Rick can edit John's data by just adding his name (if present) like this localhost/user/John

Here I just want to redirect Rick to his own profile editing page with his own data to be edited.

Currently, by applying the IF statement it does not redirect to any page but shows a blank page.

How to redirect with user data?

Aug
05
1 month ago
Activity icon

Replied to How To Authenticate Owner Only To View Profile Editing Page

@mubeenali Is it the same if I do like this...

Route::get('edit/form/{id}','[email protected]')->middleware('auth');
Activity icon

Started a new Conversation How To Authenticate Owner Only To View Profile Editing Page

I am trying to redirect the member to their editing page whenever they try to visit others.

Suppose Rick tries to visit Jack's profile editing page, he must redirect to his own editing page.

localhost/profile/edit/rick and similarly Jack would have his own link like this localhost/profile/edit/jack If Rick tries to visit the page localhost/profile/edit/jack he must redirect to localhost/profile/edit/rick

This is controller here

    public function edit(User $user)
    {
        // If statement would be here
        $user = User::find($user->id);
        return view( 'profile.editprofile', compact('user') );
    }

Basically I am trying to stop other members to edit the page. In my app, I see anyone can visit and edit the profile page for them.

Please tell me how to write if a statement in the controller...

Aug
01
1 month ago
Activity icon

Commented on Meet Birdboard

I see there is no vendor directory...but laravel asks about it.

Jul
28
1 month ago
Activity icon

Replied to Upside Down Image

I searched a lot but got nothing relevant post about it...I also came to the conclusion that pictures from the mobile phone are the reason for this ...

Thanks for the help...