Member Since 10 Months Ago

Cd.Obregón, Sonora

Experience Points
9,750
Total
Experience

250 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
64
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.

  • Community Pillar

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

Level 2
9,750 XP
Jan
23
1 day ago
Activity icon

Replied to Appending Query String Values

Ok actually you are right the Tag filter does gets lost but it does solve the issue of showing the associated tags, haha.

EDIT

So I guess everything is fine and working, added ->withQueryString to the index method.

    public function index(Category $category)
    {   
        if (request('tag')) {
        $post = Tag::where('name', request('tag'))
                ->firstOrFail()
                ->posts()
                ->simplePaginate(2)
                ->withQueryString();
    } else {
        $post = Post::latest()->simplePaginate(5);
        $category = Category::select('image_url')->get();
    }   
        return view('posts.index', [
            'posts' => $post,
            'category' => $category
        ]);
    }

And, once in the view I added the $post variable with appends:

  <span> {{ $posts->appends(['tag' == $post])->links() }} </span>

The resulting URL of paginated posts with tags: http://my-blog.test/posts?tag=thps&0=0&page=1

Activity icon

Replied to Appending Query String Values

Hm, not quite. I can view the post index and a single post, once in the single post, I can go ahead and click a tag, given the number on the simplePaginate method I can also paginate through posts with the same tag. So it is working even without withQueryString and just by using links() inside the view, is this odd? I am only using an anchor tag to view the attached tags + posts.

Activity icon

Replied to Appending Query String Values

That was the missing piece! Modified the index method like you mentioned and only had to use links() in the view. Would I need to use ->withQueryString() in the future though? Thanks so much @marianomoreyra !!

Activity icon

Replied to Appending Query String Values

I am displaying Posts but i also have the tags in the same view like this: https://imgur.com/F6fi5eD so yes I am sort of filtering posts with a given tag. Once the reader is done with the post, they can click on the tags so any posts associated with one can be showed. Thats basically what this page has: posts.show

Regarding the routes, yes here goes:

Route::get('posts', 
    [PostsController::class, 'index']
);

Route::get('/posts/category', function () {
    return view('posts.category', [
        'posts' => App\Models\Post::latest()->get()
    ]);
});

Route::resource('posts', PostsController::class)
    ->except('index', 'show')
    ->middleware('auth');

Route::get(
    'posts/{slug}',
    [PostsController::class, 'show']
);

This is my controller:

    public function index(Category $category)
    {   
        if (request('tag')) {
        $post = Tag::where('name', request('tag'))
                ->firstOrFail()
                ->posts;
    } else {
        $post = Post::latest()->simplePaginate(5);
        $category = Category::select('image_url')->get();
    }   
        return view('posts.index', [
            'posts' => $post,
            'category' => $category
        ]);
    }

And I believe this is where they merge the 2 things. But back on the view when you click on a tag it throws the exception. The way this is set up I can view the index but once you click on a tag it throws an exception about appends not exisiting in this collection: http://flareapp.io/share/dmkzgnb5

<span> {{ $posts->appends([$post])->links() }} </span>

    <div class="single-post">
        <img src="{{asset('/storage/img/post_uploads/'.$post->image_url) }}" alt="postimage"/> 
        <h1 class="header-post"> {{ $post->title }} </h1>
            {!! $post->body !!}
        <p class="space-tags"> Tags:
            @foreach ($post->tags as $tag)
                <a href="/posts?tag={{ $tag->name }}"> 
                    {{ $tag->name }}
                </a>
            @endforeach
        </p>
        <div>
            Category:
            <span style="color:#87ceeb;">
                        {{ $post->category->name }}
                </span>
        </div>
        <x-navalt/>
    </div> <!-- Single post end -->
Activity icon

Replied to Appending Query String Values

Was having no exceptions because I forgot I deleted this part:

<span> {{ $posts->appends($post)->links() }} </span>

Activity icon

Replied to Appending Query String Values

Route::get('/posts/{tag}', function () {

    $tag = Tag::simplePaginate();

    $tag->appends(['tag' => $tag]);

    return view('posts.index', compact('tag'));
});

This fixes the issue of displaying a list of posts attached to tags. If one were to visit http://my-blog.test/posts?tag=webdev

But then I was getting this whenever I wanted to view a single post.

Routing

Controller: Closure
Route name: unknown
Route parameters
    tag: hi

Middleware: web

Then I added the slug parameter to this route:

Route::get('/posts/{slug}/{tag}', function (Post $post) {

    $tag = Tag::simplePaginate();

    $tag->appends(['tag' => $tag]);

    return view('posts.index', compact('tag'));
});

And it's fixed?

I know it's near impossible for you to be sure because you would have to interact with the code and that, but in your experience, having this GET request like this, will it cost me a bug in the near future?

Activity icon

Replied to Appending Query String Values

Hi @jlrdw https://laravel.com/docs/8.x/collections#available-methods this doesn't mention "appends()" or "links()" as part of the methods available.

Activity icon

Replied to Appending Query String Values

Im only interested in the tag "name" I guess I can always pass it in the route declaration and skip building an array?

Im using the Tag model and hoping that's enough to retrieve the names im using for the anchor tag inside the posts.index, and for the usage of the appends it starts with the $posts variable, can't I use the relationship I already have on the Post model with the Tag model? like when you loop using a method on a model, for example, category. Since I've already established this one to many relationship with Category model, all I would need to do would be to insert it into the view like : $post->category->name, can't I do this inside the appends array?

Another thing that got me confused was, is this declaration for the routes or controller too? Because [email protected] seems to be requesting this variable

Activity icon

Replied to Appending Query String Values

Still doesn’t resolve it :/

Activity icon

Replied to Appending Query String Values

Hello @marianomoreyra I know and im sorry, I was going to write a longer post but I found out that I was confused about a few other things, like which models to use in the routes and I didn't know if the appends had any syntax error both in the routes or in the view.

The main view where the paginator exists is in the posts.index.

There is already a tags()in Post model, and well of course I have Tag model. but on the routes, which one do you reference? Could be convenient to use the Post since we're talking about sorting posts (but that may as well be the topic for another day, if maybe that is relatable to "best practices")

The problem at hand is this: how to use the paginator that exists in this view and still be able to have a string in the URL, in this case "tag"?

Well why did this became a problem in the first place? I think because Im displaying the paginator inside the index view and whenever I want to sort the posts by clicking on a given tag, the exceptions begin to emerge.

For example by adding this inside posts.index:

<span> {{ $posts->links() }} </span>

And after I've clicked on a post to see it's content, and select the given tag to view other posts that might have this tag also, the exception being thrown is this: http://flareapp.io/share/x7KKnKB7

Next thing I did was going over to my routes and then making a GET request for this given URL: http://my-blog.test/posts?tag=webdev So I did my best to extract it, the error could also be found here though, im not sure:

Route::get('posts/{tag}', function () {
    $tag = Tag::simplePaginate()->withQueryString();

    $tag->appends(['name' => 'tag']);

    return view('posts.index', ['tag' => $tag]);
});

And well this is the beginning of another journey through Laravel :-) Thanks! :D

EDIT - I realize now I might've overlooked the fact that I included the wrong view under the routes. (!!)

Activity icon

Started a new Conversation Appending Query String Values

Having some issues understanding:

https://laravel.com/docs/8.x/pagination#appending-query-string-values

Steps to reproduce

  1. You see a post you like on the main page and click on the title
  2. An error is shown:

Undefined variable: posts in Posts.Index

The way im trying to set up for the append method in my routes is like this:

Route::get('posts/{tag}', function () {
    $tag = Tag::simplePaginate()->withQueryString();

    $tag->appends(['tag' => 'tag']);

    return view('posts.show');
});

Associate the tag model with the simplePaginate() method and withQueryString(), maybe im not using the appends properties the right way? In the Post model that I have I also have a tags(), the relationship it has with it is a, many to many, but I don't know how this is relatable when one is trying to append something in the URL because I don't know which model to use.

I want to paginate my index of posts and this would work fine if I didn't had any tags associated, but since I do, whenever I try to use the links() method I get an error saying that links() does not exist in this collection.

Using the appends inside the view like this:

  <span> {{ $posts->appends[('tag' == $tag)]->links() }} </span>
Jan
22
2 days ago
Activity icon

Replied to Videogame Servers

That's interesting. HTTP is definitely something worth knowing for the web development, wish there was a GUI of some kind for reviewing requests but I guess that's basically a browser? haha! On modern videogames one thing i dislike is the "Matchmaking" concept.. im from the old days where you had a list of lobbies and each of them had a list of games and you could select which one to join, if you didn't liked that one, you could always leave and join another room.

Since videogames are much powerful than what they used to be, and like you mention speed is of the essence, require a lot of memory, and a powerful processor, I guess having a list of games would only make the experience slower? Can you say that's the case or is it more of a "trending" concern :-)

Activity icon

Started a new Conversation Videogame Servers

This topic comes out of pure curiosity. Do servers used for onliine play, in videogames, do they also use POST and GET requests? Is it THAT simple? What do they use? I have a notion they're unrelated with the HTTP protocol. So what's a good way to understand that? Cheers!

Jan
21
3 days ago
Activity icon

Replied to Custom Filtering Data

Thanks!

Activity icon

Replied to Custom Filtering Data

Is there a course on this at Laracsts @jlrdw ?

Activity icon

Started a new Conversation Custom Filtering Data

If all I have is this:

    public function searchByCategory(Post $post, Category $category)
    {   
        $post = Post::where('category_id', $category->id)
                    ->latest('id')
                    ->paginate(8);
        $category = Category::get();
        return view('posts.category', ['posts' => $post, 'category' => $category]);
    }

And im using it to see all posts regarding a category, would it be wise to create a controller just for this? I was using it inside my PostsController but I don't want it to be mixed with the CRUD essentials.. This works though, I don't think it's the most advanced thing ever and I dont neccesarily need it but im mainly looking for suggestions :-)

I mean, when I say it's not the most advanced thing ever is because you look at the data through an <a href=""> anchor tag element:

            <span> Category: </span>
                <a href="{{ route('posts.category', $post->category) }}"> 
                    {{ $post->category->name }} 
                </a>
Jan
20
4 days ago
Activity icon

Replied to Tailwind Styles Not Loading

So, from this:

mix.js('resources/js/app.js', 'public/js')
    .vue()
    .sass('resources/sass/app.scss', 'public/css')
    .tailwind();

To this: (?)

mix.js('resources/js/app.js', 'public/js')
    .vue()
     .postCss("resources/css/app.css", "public/css", [
       require("tailwindcss"),
]);

Sorry, I forgot to add these important lines as well !

Activity icon

Replied to Tailwind Styles Not Loading

Unless the classes were given different names throughout the course of time, I still don't know why there would be a warning on them.. for example consider this: https://imgur.com/5TUg5kM

Activity icon

Started a new Conversation Tailwind Styles Not Loading

Hey guys, so as im following the Laravel, Vue and SPA's course I've found out that im not loading Tailwind correctly yet the build was done succesfully, in fact in the sass/app.css directory (resources/sass/app.css) underlines these 3 variables in yellow:

@tailwind base;
@tailwind components;
@tailwind utilities;

Warning is this: Unknown at rule @tailwindscss(unknownAtRules)

Since Iv'e never used Sass before, I sincerely don't know if I need to compile it first yet we use the app.scss, and this was not explained in the course, do I need to compile it first? Why would it not be loading if the build was 'succesful' ? It could be that the css is not loaded properly so here goes that:

web/routes.php:

Route::get('/{any?}', function () {
    return view('app');
});

CSS link (app.blade.php):

<link rel="stylesheet" href="/css/app.css">
Jan
19
5 days ago
Activity icon

Replied to Increasing Composer Memory

I just want to avoid a global update, does this happen with composer I can't recall

Activity icon

Started a new Conversation Increasing Composer Memory

Im trying to follow this series https://laracasts.com/series/laravel-vue-and-spas and in doing so, and at least for Laravel 8, Vue doesn't come pre-installed, so I ran composer require laravel/ui but I get the following error:

According to: https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors, I should increase the memory limit by "-1" so its "unlimited" or something via the php.ini file but I dont know where that is.

Is there any way to open it through the terminal? I am on a Macbook. Thanks!

Activity icon

Replied to Modal For 2 Methods

Are Vue components helpful in this situation? Would seem like a great excuse though.

Activity icon

Started a new Conversation Modal For 2 Methods

Hey folks, I already have a modal and currently it's being used for storing data, how can I launch the same window/modal but now for updating my data?

    <script>
        var modal = document.getElementById("categoryModal");
        var btn = document.getElementById("addBtn");
        var span = document.getElementsByClassName("close-modal")[0];

        btn.onclick = function() {
            modal.style.display = "block";
        }

        span.onclick = function() {
            modal.style.display = "none";
        }

        window.onclick = function(event) {
            if (event.target == modal) {
                modal.style.display = "none";
            }
        }
    </script>

What gets displayed in the view it's a form and this one uses an id of categoryModal this is where the form, that creates a resource, is located at. IF i wanted to use my update function:

  • a) How can I reuse the same javascript that I have?

  • b) Given the JavaScript, is it possible to reuse?

  • c) Iv'e never done this before and for DRY purposes this is somewhat complex for me to grasp

Having said that, a few initial pointers/directions would be fine. Thanks!

Activity icon

Replied to VUE Is Regret.

Complaining about something im not qualified talking about, based on the primary fact of "I don't understand it", the next day or the very first minute after posting it, would feel pretty regretful, to me. Just because you "can't do it" doesn't mean you NEED to be a victim about it..

You have an opinion? Good.

Most folks in here love helping other people. I have been a witness of that myself. Everything of course in a public forum is suggested until you break a rule, do as others do and try to be as polite as you possibly can, it'll be good for you, I promise!

Jan
18
6 days ago
Activity icon

Replied to Bad Method Call On Save()

What should the action contain? @newbie360

Activity icon

Replied to Bad Method Call On Save()

I will try this, and yes I will search for more info about this. Also, thanks for that git repo.

Activity icon

Replied to Bad Method Call On Save()

And the form doesnt show any of the old values, hehe not in the two for one errors :-(

Activity icon

Replied to Bad Method Call On Save()

@newbie360 the problem has been fixed but I now receive another exception that has to do with the attachment of tags.. not sure if by only changing names somewhere?

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-1' for key 'post_tag_post_id_tag_id_unique' (SQL: insert into post_tag (created_at, post_id, tag_id, updated_at) values (2021-01-19 00:39:54, 1, 1, 2021-01-19 00:39:54))

Activity icon

Replied to Bad Method Call On Save()

By removing ->parameters(['posts' => 'slug']) I can't see the old values on the form.

Activity icon

Replied to Bad Method Call On Save()

Route:

Route::resource('posts', PostsController::class)
    ->except('index', 'show')
    ->parameters(['posts' => 'slug'])
    ->middleware('auth');

Model

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $fillable = [
        'title',
        'body',
        'slug',
        'image_url',
        'category_id'
    ];

    protected $guarded = [];

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

    public function author()
    {
        return $this->belongsTo('App\Models\User', 'user_id');
    }
    
    public function category()
    {
        return $this->belongsTo('App\Models\Category');
    }

    public function tags()
    {
        return $this->belongsToMany('App\Models\Tag')->withTimeStamps();
    }
    
    use HasFactory;
}

Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Post;
use App\Models\Tag;
use App\Models\Category;
use Illuminate\Pagination\Paginator;

class PostsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   
        if (request('tag')) {
        $post = Tag::where('name', request('tag'))
            ->firstOrFail()->posts;
    } else {
        $post = Post::latest()->simplePaginate(13);
        $category = Category::select('image_url')->get();
    }   
        return view('posts.index', [
            'posts' => $post
        ]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {   
        $category = Category::all();
        
        return view('posts.create', [
            'tags' => Tag::all(),
            'category_id' => $category
        ]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validatePost();

        $post = new Post(request(['title', 'body', 'slug', 'image_url', 'category_id']));
    
        $fileExtension = request('image')->getClientOriginalName();
        $fileName = pathInfo($fileExtension, PATHINFO_FILENAME);
        $extension = request('image')->getClientOriginalExtension();
        $newFileName = $fileName . '_' . time() . '.' . $extension;
        $imgPath = request('image')->storeAs('public/img/post_uploads', $newFileName);
    
        $user = auth()->user();
        $post->image_url = $newFileName;
        $post->user_id = $user->id;
    
        $post->save();
        $post->tags()->attach(request('tags'));
    
        return redirect('/posts');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show(Post $slug)
    {
        $category = Category::get();
        $post = Post::get();
        return view('posts.show', ['post' => $slug, 'category' => $category]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Post $slug)
    {   
        $post = Post::find($slug);
        $category = Category::all();

        return view('posts.edit', [
            'post' => $slug,
            'tags' => Tag::all(),
            'category_id' => $category
        ]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Post $slug, Request $request)
    {   
        dd($this->validatePost());

        $post['user_id'] = auth()->id();

        if ($request->has('image')) {
            $fileExtension = request('image')->getClientOriginalName();
            $fileName = pathInfo($fileExtension, PATHINFO_FILENAME);
            $extension = request('image')->getClientOriginalExtension();
            $newFileName = $fileName . '_' . time() . '.' . $extension;
            $imgPath = request('image')->storeAs('public/img/post_uploads', $newFileName);

            $post->image_url = $newFileName;  
            $post->save();
        }
        
        $post->save();

        $post->tags()->attach(request('tags'));

        return redirect('posts/' . $post->slug);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $post = Post::findOrFail($id);

        $oldImage = public_path() . '/storage/img/post_uploads/' . $post->image_url;
        if (file_exists($oldImage)){
            unlink($oldImage);
        }

        $post->delete();
        return redirect('/dashboard/posts/');
    }

    protected function validatePost() 
    {
        return request()->validate([
            'title' => ['required', 'max:255'],
            'body'  => ['required'],
            'slug'  => ['required', 'max:100'],
            'tags' => ['exists:tags,id'],
            'category_id' => ['required']
        ]);
    }
}
Activity icon

Replied to Bad Method Call On Save()

Thanks! I will.

Activity icon

Replied to Bad Method Call On Save()

This is literally so hard to understand. I'll look into that - actually I do get my array when I try to dd($this->validatePost()); and yes, Iv'e settled the getRouteKeyName method to be slug.

Activity icon

Replied to Bad Method Call On Save()

Yes, actually by revising from the "Laravel from Scratch" series, I saw how the validation comes first and then the rest of the logic... so this is it's current state:

    public function update(Post $slug, Request $request)
    {   
        $this->validatePost();

        $post = Post::find($slug);

        $post['user_id'] = auth()->id();

        if ($request->has('image')) {
            $fileExtension = request('image')->getClientOriginalName();
            $fileName = pathInfo($fileExtension, PATHINFO_FILENAME);
            $extension = request('image')->getClientOriginalExtension();
            $newFileName = $fileName . '_' . time() . '.' . $extension;
            $imgPath = request('image')->storeAs('public/img/post_uploads', $newFileName);

            $post->image_url = $newFileName;  
            $post->save();
        }
        
        $post->save();

        $post->tags()->attach(request('tags'));

        return redirect('posts/' . $post->slug);
    }
Activity icon

Replied to Bad Method Call On Save()

Hmm by not using the update() method anymore, that went away but now the same occurs with the save()... so this is weird

Activity icon

Replied to Bad Method Call On Save()

It's on the flareapp URL :-) - but here goes anyway:

    public function update(Post $slug, Request $request)
    {   
        $post = Post::find($slug);

        $post->update($this->validatePost());

        $post['user_id'] = auth()->id();

        if ($request->has('image')) {
            $fileExtension = request('image')->getClientOriginalName();
            $fileName = pathInfo($fileExtension, PATHINFO_FILENAME);
            $extension = request('image')->getClientOriginalExtension();
            $newFileName = $fileName . '_' . time() . '.' . $extension;
            $imgPath = request('image')->storeAs('public/img/post_uploads', $newFileName);

            $post->image_url = $newFileName;  
            $post->save();
        }
        
        $post->save();

        $post->tags()->attach(request('tags'));

        return redirect('posts/' . $post->slug);
    }
Activity icon

Started a new Conversation Bad Method Call On Save()

So, whenever im trying to update something I get this message:

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

Im trying to update resources and here goes the main one, do I still need to request a validation? Because "request()" requires an array, this is the validation method:

    protected function validatePost() 
    {
        return request()->validate([
            'title' => 'required|max:255',
            'body'  => 'required',
            'slug'  => 'required|max:100',
            'tags' => 'exists:tags,id',
            'category_id' => 'required'
        ]);
    }

Iv'e also tried changing the resulting of the "=>" to arrays, like this:

    protected function validatePost() 
    {
        return request()->validate([
            'title' => ['required', 'max:255'],
            'body'  => ['required'],
            'slug'  => ['required', 'max:100'],
            'tags' => ['exists:tags,id'],
            'category_id' => ['required']
        ]);
    }

...but Im still getting some kind of exception. So, yes I would like to use it even if it's not required to validate, it's something I dont understand, I mean once the data went into the database and got stored, does it really matter at that point? The only way I have for the data to be validated, inside the "update" method is like this:

$post->update($this->validatePost());

Thanks, im doomed I know :-)

https://flareapp.io/share/Lm8OGkb5

Jan
14
1 week ago
Activity icon

Replied to Can I Dive Into Laravel With Basic Php Knowledge

Iv'e begun to understand theres more than knowing the tools, Laravel is a tool, PHP is a programming language that was used to build Laravel, so therefore it's another tool. The next question you might want to ask yourself is, what can I do with a framework like this one?

You could use it as a Full Stack Framework or you could use it as API backend, so in terms of what your'e already familiar with, what do you best suceed at, right now? If you want to know more about web apps that have a database and things like that then you might be interested in things like HTTP protocol, databases, a server side programming language and I think Procedural Programming (this is just a way of organizing code turns out its what most people use in the web)

https://laravel.com/docs/8.x#meet-laravel

Whether you are new to PHP or web frameworks or have years of experience, Laravel is a framework that can grow with you. We'll help you take your first steps as a web developer or give you a boost as you take your expertise to the next level. We can't wait to see what you build.

https://laravel.com/docs/8.x#laravel-the-fullstack-framework

Activity icon

Started a new Conversation Web Development And PDO

I need a few books recommendations to learn how to think about my code, how to organize it and how to visualize it in my head before trying to write anything. I mean anything from HTTP, to PHP, PDO, MySQL. If better, whats a good course to enroll myself if I want to get a good foundation on these topics? Thanks!

Jan
13
1 week ago
Activity icon

Started a new Conversation Creating Default Object From Empty Value?

Hello guys, what is the cause for this error? https://flareapp.io/share/pPv4JZ85 According to StackOverflow https://stackoverflow.com/questions/8900701/creating-default-object-from-empty-value-in-php its a PHP warning that one can get rid of? But why is this?

Jan
12
1 week ago
Activity icon

Started a new Conversation Cant Select My Own Data, Selected "tags" Is Invalid

Hey guys im getting an error for one of my <select> items from a Form I have. Im trying to select a tag that gets displayed on the box and when I hit the submit button the @error variable displays me a message that says "The selected tags is invalid. " I already checked the database and it's a valid data, all im doing here is trying to update the record but I can't get through the request because the front-end jumps first.

By the way how can I have these items already selected on the element? Thanks!

            <div class="tags">
            <label for="tags">Tags</label>
            <select
                name="tags[]"
                id="tags"
                multiple>
                @foreach($tags as $tag)
                    <option value="{{$tag->id}}">
                        {{ $tag->name }}
                    </option>
                @endforeach
            </select>
            @error('tags')
                <p class="is-danger"> {{ $message }} </p>
            @enderror
            </div> <!-- Tag field end -->
Jan
08
2 weeks ago
Activity icon

Replied to Installed Via Composer But Still Says Missing

Check your php version like this: composer -vvv about 2>&1 | grep "PHP" or I believe you can also try it like this, and im paraphrasing here (source: https://stackoverflow.com/questions/33064160/how-composer-check-php-version):

When using the command composer the cli will first resolve which binary to use. By running which composer you can find what binary that is.

 which composer

outcome should be something like:

/usr/bin/composer

Once you know that, you can open the file, for instance using vim: vim /usr/bin/composer (generally it takes super user access to modify binaries so you shouldn't be able to mess composer up doing that).

You can then call that php binary directly to verify its version:

usr/bin/php -v

What I don't know though is how to update that version (in case it's a lower number version), but that's what I would do, check for the PHP version.

Activity icon

Replied to Auth And No-auth Routes, Route Grouping

Worry not! There is something wrong with my create method so the post to this question is invalid, I guess.. we can still talk about how amazing Route::resource is! But, yeah. Have a good day!

Activity icon

Replied to Auth And No-auth Routes, Route Grouping

Adding to this

Running php artisan route:list does shows me all the routes, including create. https://imgur.com/1JKaRpN

Activity icon

Started a new Conversation Auth And No-auth Routes, Route Grouping

Recently I adopted the wonderful convention of using Route::resource and this means that any parameter or whatever that I add to this line, will be included to all my methods, but im looking to exclude 2 routes ('show' and 'index') from being authenticated. So if this is the resource route path:

Route::resource('posts', PostsController::class)->parameters(['posts' => 'slug'])->middleware('auth');

One way of grouping the auth routes should look like this:

Route::group(['middleware' => ['auth']], function () { 
    Route::get('posts/create', 'App\Http\Controllers\[email protected]');
    Route::post('posts/{slug}', 'App\Http\Controllers\[email protected]');
    Route::put('posts/{slug}', 'App\Http\Controllers\[email protected]');
    Route::get('posts/{slug}/edit' , 'App\Http\Controllers\[email protected]');
});

So any route that needs authentication is grouped. And then those that should be for everyone else to see, something like this:

Route::get('posts', function () {
    return view('posts/index', [
        'posts' => App\Models\Post::all()
    ]);
});

Route::get('posts/{slug}', 'App\Http\Controllers\[email protected]');

And this seems to be working until I went and test them all out. So far create is the only one that throws a 404. According to this https://stackoverflow.com/a/54199325 Im able to place any route needing authentication in the routes/web/auth.php file, doing this requires to go to app\Providers\RouteServiceProvider.php and look for a method called mapWebRoutes(), but there is no method with this name, so either this is already implemented or there is something wrong with my code. Perhaps a typo? Thanks!

Jan
07
2 weeks ago
Activity icon

Replied to Names To Avoid On URL's

This article was very much useful. Thanks!

Activity icon

Replied to Names To Avoid On URL's

Starting to get the bigger picture then.

Activity icon

Replied to Names To Avoid On URL's

What's the simplest authentication system for Laravel? Is it laravel auth? I mean there's Fortify and Jetstream has that included but I believe the command make:auth delivers that Laravel built-in system. Looking for a basic user roles where the user could sign up but without access to backend just edit some their profile

Activity icon

Replied to Names To Avoid On URL's

True. Might be my imagination then but then again if I were to access illegally to a webserver I would have to use a lot of imagination. But I do understand where your reply is coming from, I mean technically you won't secure a webapp just by deciding to add a "obscure" name to a path URL. I figured I had to ask... :-) if anyone has more insight on this, an article, blog post, youtube video please share! Cheers!

Activity icon

Started a new Conversation Names To Avoid On URL's

Hey guys is it recommended to avoid some names in the URL's for security reasons? Names like "adminpanel" or "dashboard" or something indicating that there is a system or a database in place.

Jan
05
2 weeks ago
Activity icon

Replied to 502 Bad Gateway

Your answer helped me get the ball rolling. Thanks.