Email:   Password:
Blog :: Technical Learning by Thomas Riemer
RSS 2.0   RSS 1.0   Atom
Laravel II   (PDF)
Posted March 25th, 2024

Basic attempt to do a simple crud application.
1. So you can install laravel globally
composer global require laravel/installation
This installs the laravel binary in ${HOME}/.config/composer/vendor/bin
Its useful to put this as a separate user. I chose <b>composer</b>
useradd composer
su - composer
composer global require laravel/installation
chmod 777 /home/composer
So other users can use the laravel installation binary, add the location to
Path. edit /etc/profile.d/
export PATH=$PATH:/home/composer/.config/composer/vendor/bin

2. starter kits.   So following a tutorial for laravel, and as usual its out of data.   So to create a project:
laravel new posty
And now it asks me for a "starter kit"
None, Breeze, Jetstream.
I chose None

And now it asks me the testing framework
Pest, or PHPUnit
I chose Pest - it was the default
And now whether I want to initialize a git repository

And now it asks me for what database to use
Mysql, Mariadb, PostgresSQl, SQLite, SQL Server

3. <b>php artisan</b> lists all the various things you can
do with artisan e.g. laravel

4. So <b>blade</b> The laravel default template engine.
   First thing is to be introduced to Layouts....
   a. php artisan make:component Layout
      // this generates a Layout component with
      // resources/views/controller/layout.blade.php
    b. Here is a sample layout controller (resoure/views/controller/layout.blade.php
    <title>{{ $title ?? 'Example Website' }}</title>
    <link rel="stylesheet" href="{{ asset('/css/app.css') }}">
      <h3>Welcome to my website</h3>
    {{ $slot }}
      <hr />
      &copy; 2023

c. So a content php file is called a view.
    each file view is named viewname.blade.php
   example welcome.blade.php

d. Sample welcome.blade.php
   <x-slot name="title">
    Home | Example Website
    <h1>Hello World!</h1>
    <p>Lorem ipsum dolor sit amet consectetur adipiscing elit. Hic, aut?</p>
    <button class="btn">Get Started</button>
    the magic <b>x-layout</b> tag tells the template to use the layout
    the <b>x-slot</b> tag lets you pass alternate content to the layout
    the code {{ $title ?? 'Example Website' }} says to show the variable
    title if it exists otherwise "Example Website"
    The x-slot allows you to overlayout that.

5. tailwindcss.  Install via npm
npm install tailwindcss
So... an aside, you will see warnings on npm if you are pulling from
the http vs https registry.  You can configure your registry in npm

npm config set registry

6. I use emacs... but all the samples use code visual studio
 Download from

7. models, controllers and crud oh my.

   So by default the laravel resource code for controllers
   doesn't handle POSTs well.

   So - you make a model
   php artisan make:model Product
   php artisan make:controller ProductController --resource
   So if you use
   Router::resource("product", ProductController::class);
   you can't just use POST from your html form post.
   from the docs its supposed to be PUT method, but PUT method
   makes the fields passed as a url - which means you hit a limitation
   method on requests where the content is over a certain limit.

   So vendor/laravel/framework/src/Illuminate/Routing/ResourceRegistrar.php
   line 493, add "POST" in the methods that can match.

   So now you can use POST. really stupid.. I ended up having to chance
   down where it matches the code in laravel. 2 1/2 hours later.

   Unbelievable the number of simple projects that purport to show
   a simple crud example in laravel.   Half of them do not have
   the routing information provided.   Some clearly are from previous
   versions of laravel.

   It would be really nice if it wrote the actual functions in the
   controller when you do --resource

Copyright © 2024 Mind Contract, Inc.   All Rights Reserved
For more information call or email 720-883-1866
Powered By: Build a Member