#confused with laravel code
19 messages · Page 1 of 1 (latest)
Hello everyone
i am confused with that code
what does that mean ??
full code : https://www.itsolutionstuff.com/post/laravel-10-crud-application-example-tutorialexample.html
break it down, it does exactly what written to do.
return is obvious basic php, view() helper method resolves the component that is returned, using dot / folder syntax, compact() helper method creates and array from the variables/values which are passed from the controller to the view. with() helper also passes data from the controller to the view however it uses key value pairs to do so (slightly different).
Did you need a more granular answer including what the values mean inside the methods?
Really though, if you are using an IDE you should be able to hover over the method & get an explanation of what it does...
yeah
what is ('page', 1) - 1) * 5)
You are getting the value of the ‘page’ key from the request & if it doesn’t exist it defaults to 1. Then you subtract 1 from that number & then you times it by 5 & then with() method returns the calculated number with the key of ‘i’. I’m not sure what this is for, maybe a pagination offset
It'll get an input value, see https://laravel.com/docs/10.x/requests#retrieving-an-input-value. Then it does some calculation
I like your explanation better!
is this a good practice ?
I don’t know the context, it’s hard to say. I can’t see anything that looks really bad. It’s just different to how I would return things, so yeah depends on the context, what this is for.
i am new to laravel and absolutely have no idea what that code mean
so I am making crud as starter project
Start with a series based on foundational knowledge & read the docs right through. https://laracasts.com/series/laravel-8-from-scratch
This will help you understand the the concepts specific to Laravel.
We don't learn tools for the sake of learning tools. Instead, we learn them because they help us accomplish a particular goal. With that in mind, in this series, we'll use the common desire for a blog - with categories, tags, comments, email notifications, and more - as our goal. Laravel will be the tool that helps us get there. Each lesson, ge...
Your not going to learn all that is needed doing that CRUD blog tutorial , you will probably just be more confused.
thank you for the help
Yeah this. Skimmed through the "tutorial" and it doesn't look like they explain anything they do. They just say like "we need controllers" and then there's a snippet of said controller, no explaining what it all does. If you're a beginner and just copy paste that into your project, things might work but you'd have no clue what is actually happening. So read through the docs, read through the code, try to understand it, if you see method calls you don't know what they do search through the docs to find out
(Cc @stark sinew)