laravel life cycle

 


The Laravel framework follows a specific lifecycle when handling incoming HTTP requests and generating responses. This lifecycle involves multiple steps and components working together to execute the requested action. Here's an overview of the typical Laravel request lifecycle:

  1. Routing: The lifecycle begins with the routing process, where the framework matches the incoming request's URL to the appropriate route defined in the routes file (routes/web.php or routes/api.php). The route specifies the controller method or closure that should be executed.

  2. Middleware: Middleware are intermediate layers that can process the request before it reaches the controller. Middleware can perform tasks such as authentication, authorization, logging, and more. You can apply middleware globally or to specific routes.

  3. Controller Dispatch: Once the route is matched and middleware are applied, the associated controller method is dispatched. The controller contains the logic for processing the request and generating a response.

  4. Request Handling: Within the controller method, you can access the request object, which holds information about the incoming HTTP request (such as input data, headers, and files).

  5. Validation: Laravel provides a validation mechanism to ensure the incoming data meets specific rules. You can define validation rules within the controller or in separate request classes.

  6. Action Execution: The controller method executes the necessary actions, which could involve retrieving data from a database, performing calculations, or interacting with services.

  7. Response Generation: After processing the request, the controller returns a response. This response can be in various formats, including HTML views, JSON, or files.

  8. Middleware (Outgoing): Once the controller has generated a response, it passes through any outgoing middleware. Outgoing middleware can modify the response or perform actions before it's sent to the client.

  9. HTTP Kernel: The HTTP kernel is responsible for managing the request and response flow. It handles middleware, including both incoming and outgoing middleware.

  10. Response: The final response is sent back to the client, completing the request lifecycle.

Throughout this lifecycle, Laravel provides hooks and events that allow developers to customize and extend various stages of the process. This flexibility makes it possible to implement additional functionality, such as logging, caching, or custom authentication mechanisms.

Remember that while this overview provides a general idea of the Laravel request lifecycle, the actual implementation and details may vary based on the specific version of Laravel you're using and any modifications you've made to the default configuration

traits

 traits 

triat has single inheritance

it will show error because a function repeated in two traits 


<!DOCTYPE html>

<html>

<body>



<?php

trait message1 {

public function msg1() {

echo "OOP is fun! ";

}

public function msg2() {

echo "OOsssP reduces code duplication!";

}

}



trait message2 {

public function msg2() {

echo "OOP reduces code duplication!";

}

}



class Welcome {

use message1;

}



class Welcome2 {

use message1, message2;

}



$obj = new Welcome();

$obj->msg1();

echo "<br>";





$obj2 = new Welcome2();

$obj2->msg1();

$obj2->msg2();

?>


</body>

</html>

no two traits same function  if we import
error fateal error:

The error will occur in this part of the code:

$obj2 = new Welcome2(); $obj2->msg1(); $obj2->msg2(); // This line will cause an error
php
$obj2 = new Welcome2(); $obj2->msg1(); $obj2->msg2(); // This line will cause an error

The error message you might encounter is something like:

Fatal error: Trait method msg2 has not been applied, because there are collisions with the method in class Welcome2
sql
Fatal error: Trait method msg2 has not been applied, because there are collisions with the method in class Welcome2



working code 

<!DOCTYPE html>
<html>
<body>

<?php
trait message1 {
public function msg1() {
echo "OOP is fun! ";
}
}

trait message2 {
public function msg2() {
echo "OOP reduces code duplication!";
}
}

class Welcome {
use message1;
}

class Welcome2 {
use message1, message2;
}

$obj = new Welcome();
$obj->msg1();
echo "<br>";


$obj2 = new Welcome2();
$obj2->msg1();
$obj2->msg2();
?>
</body>
</html>


s

static function and whats the uses and how to write


write a static function  in a controller


public static function basics_form(){
echo '
<div class="container">
<form action = "create_article" method = "post">
<input type = "hidden" name = "_token" value = "'; echo csrf_token(); echo '">
<div class="form-group">
<label for="title">Title <span class="form-required" title="This field is required.">*</span></label>
<input required type="text" id="title" placeholder="Enter The Title" name="title" value="" size="50" maxlength="50" class="form-control required">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<textarea required type="text" id="edit-name" placeholder="55" name="content" value="" size="250" maxlength="250" class="form-control required"> </textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>


';
}


and 

how to call that static function in view blade 

<?php use \App\Http\Controllers\AdminController; ?>
{{ AdminController::basics_form() }}


without creating an instance we can call directly that static function

class MathHelper {

    public static function add($num1, $num2) {

        return $num1 + $num2;

    }

}


$result = MathHelper::add(5, 3); // Calling static method directly



In this example, the add() method is defined as static in the MathHelper class. You can call it directly using MathHelper::add(5, 3) without creating an instance of the MathHelper class.


how to call a static function in same class

class MathHelper { public static function add($num1, $num2) { return $num1 + $num2; } public function vamsi() { $result = self::add(5, 3); return $result; } }






ss

laravel

 class A {

hasonethorugh

we can extend classes but why we are using trait

multiple try cathc method

multiple inheritance

multiple try catch

multiple catch

hsone through

public function m() {
return 'x';
}
}
class B extends A {
public function m() {
return 'y';
}
}



$instB = new B();
echo $instB->m();

$instA = new A();
echo $instA->m();

<?php
error_reporting(E_ALL);
class A {
public static function m() {
echo 'M';
}
public function n() {
// Write code to access m()
}
}

$instA = new A();
$instA->n();

class A {
public function m() {
return;
}
}
class B extends A {
public function n() {
return;
}
}
class C extends B {
public function o() {
return;
}
}
You11:45 AM
echo ::m();

XSS
function doSomething($a, ...$x) {
// some operation
}

=======

$a = 5;
$b = 'a';
$c = 'b';

echo $$c;
======

$b = 5;
var_dump($b++ == ++$b);
echo $b;

$a = [
'name' => 'A',
'age' => 13
]
[
'A',
13
]

hasOneThrough
Posts
-----
id
title
desc

Comments
--------
id
post_id
text
author

$post = Post::find(1);

Get the authors for the comment only
hasmany('comment:classs,"select('name"));
PRI- Vamsi (Sean Atkinson)

laravel nova

 download the file from code list cc

then

create laravel nova-app

composer install


composer update

dump-autoload

composer.json

"repositories": [
{
"type": "path",
"url": "./nova"
}
],
"require": {
"php": "^7.3|^8.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"laravel/nova": "*"
},

visit this url

http://127.0.0.1:8000/nova/resources/users/new

s

sudo apt-get install php-dom

sudo apt install php-zip

sudo apt install php-mysql


php artisan nova:user
php artisan nova:publish


php artisan route:list





all

898 composer create-project laravel/laravel nova-app
1899 composer install
1900 cd nova-app/
1901 composer install
1902 composer update
1903 which php.ini
1904 php --ini
1905 cd ../../
1906 cd hpanel/
1907 sh restart.sh
1908 cd nova-app/
1909 composer install
1910 php --ini
1911 sudo apt-get install php-dom
1912 sudo apt autoremove
1913 composer install
1914 composer update
1915 composer dump-autoload
1916 sudo chmod -R 777 storage
1917 sudo chmod -R 777 storage/logs
1918 php artisan key:generate
1919 composer update
1920 sudo apt install php-zip
1921 php -m | grep zip
1922 php -v
1923 composer update
1924 php artisan nova:install
1925 php artisan migrate
1926 sudo chmod -R 777 storage/logs
1927 php artisan migrate
1928 php -m | grep pdo_mysql
1929 php artisan optimize:clear
1930 php artisan config:clear
1931 php --ini
1932 php -m | grep pdo_mysql
1933 php artisan migrate
1934 cd ..
1935 sh restart.sh
1936 sh stop.sh
1937 sh start-php-my-admin.sh
1938 sudo lsof -i:80
1939 sudo kill 996
1940 sudo lsof -i:80
1941 sudo kill 76841
1942 sudo lsof -i:80
1943 sh restart.sh
1944 sh start-php-my-admin.sh
1945 php artisan migrate
1946 cd nova-app/
1947 php artisan migrate
1948 sudo lsof-i:80
1949 history
1950 sudo lsof -i:80
1951 sudo kill 10142
1952 sudo lsof -i:80
1953 sudo lsof -i:81
1954 sudo lsof -i:8082
1955 sudo lsof -i:8083
1956 cd ../
1957 sh restart.sh
1958 sh clear-all-cache.sh
1959 php artisan serve
1960 php artisan storage:link
1961 npm install
1962 cd nova
1963 npm install
1964 cd ../
1965 sh clear-all-cache.sh
1966 php artisan serve
1967 php artisan optimize:clear
1968 sudo chmod -R 777 storage
1969 php artisan optimize:clear
1970 sh clear-all-cache.sh
1971 php -v
1972 sudo apt-get install php7.4.3-mysql
1973 sudo apt install php-mysql
1974 php artisan migrate
1975 php artisan config:clear
1976 php artisan nova:user
1977 php artisan serve
1978 php artisan optimize:clear
1979 sudo chmod -R 777 storage
1980 php artisan optimize:clear
1981 sudo chmod -R 777 bootstrap/cache
1982 php artisan optimize:clear
1983 php artisan nova:publish
1984 php artisan view:clear
1985 php artisan clear-compiled
1986 php artisan route:clear
1987 php artisan config:cache
1988 composer dump-autoload
1989 php artisan route:list

github clone

 git clone https://username:token@github.com/username/repo.git


go to settings

developer settings

token classic

generate token

use that toke above to pull

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...