Diego  Elizondo

Diego Elizondo

1656707640

Cómo Agregar RSS Feed En Laravel 9

RSS significa Really Simple Syndication y una fuente RSS es un archivo XML que tiene una lista de URL actualizadas de su sitio web. Puede utilizar la fuente RSS para el envío automático de actualizaciones de notificaciones por correo electrónico.

En este ejemplo, crearemos una tabla de publicaciones con título, slug y cuerpo. Luego crearemos una fábrica para publicaciones ficticias. Luego, generaremos un archivo XML y enumeraremos todas las URL para las publicaciones. Es un ejemplo muy básico. así que sigamos y obtendrá un archivo de mapa del sitio para su sitio web y lo enviará a la herramienta del webmaster.

Sigamos los pasos a continuación:

Paso 1: Instalar Laravel

Este paso no es obligatorio; sin embargo, si no ha creado la aplicación laravel, puede continuar y ejecutar el siguiente comando:

composer create-project laravel/laravel example-app

Paso 2: crear un modelo y una migración posterior

En este paso, crearemos la migración y el modelo. Entonces, ejecutemos el siguiente comando para crear una tabla de publicaciones.

php artisan make:migration create_posts_table

A continuación, simplemente actualice el código debajo del archivo de migración.

base de datos/migraciones/create_posts_table.php

<?php
  
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
  
return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('slug');
            $table->text('body');
            $table->timestamps();
        });
    }
  
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
};

Luego ejecute la nueva migración creada con el siguiente comando:

php artisan migrate

Ahora, ejecute el siguiente comando para crear el modelo Post.

php artisan make:model Post

Luego actualice el siguiente código al modelo Post.

aplicación/Modelos/Post.php

<?php
  
namespace App\Models;
  
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
  
class Post extends Model
{
    use HasFactory;
  
    protected $fillable = [
        'title', 'slug', 'body'
    ];
}

Paso 3: crear una fábrica de publicaciones

En este paso, crearemos la clase Post factory y generaremos registros ficticios usando el comando tinker. así que ejecutemos el siguiente comando para crear una fábrica posterior.

php artisan make:factory PostFactory

A continuación, copie el código siguiente y actualice el archivo PostFactory.php.

base de datos/fábricas/PostFactory.php

<?php
  
namespace Database\Factories;
  
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Post;
use Illuminate\Support\Str;
  
/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Post>
 */
class PostFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Post::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'title' => $this->faker->text(),
            'slug' => Str::slug($this->faker->text()),
            'body' => $this->faker->paragraph()
        ];
    }
}

Luego, simplemente ejecute el comando tinker y cree publicaciones ficticias.

php artisan tinker
App\Models\Post::factory()->count(30)->create();

Paso 4: Crear Ruta

En este paso, crearemos una ruta sitemap.xml. así que vamos a agregarlo.

rutas/web.php

<?php
  
use Illuminate\Support\Facades\Route;
  
use App\Http\Controllers\RSSFeedController;
   
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
    
Route::get('feed', [RSSFeedController::class, 'index']);

Paso 5: Crear controlador

En este paso, tenemos que crear un nuevo controlador como RSSFeedController con index(). obtendremos todas las publicaciones y las pasaremos al archivo blade. devolveremos la respuesta como un archivo xml. así que actualicemos el siguiente código:

app/Http/Controllers/RSSFeedController.php

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use App\Models\Post;
  
class RSSFeedController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $posts = Post::latest()->get();
  
        return response()->view('rss', [
            'posts' => $posts
        ])->header('Content-Type', 'text/xml');
    }
}

Paso 6: Crear archivo de vista

En el último paso, creemos rss.blade.php para mostrar todas las publicaciones y coloque el siguiente código:

recursos/vistas/rss.blade.php

<?=
'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
?>
<rss version="2.0">
    <channel>
        <title><![CDATA[ ]]></title>
        <link><![CDATA[ https://your-website.com/feed ]]></link>
        <description><![CDATA[ Your website description ]]></description>
        <language>en</language>
        <pubDate>{{ now() }}</pubDate>
  
        @foreach($posts as $post)
            <item>
                <title><![CDATA[{{ $post->title }}]]></title>
                <link>{{ $post->slug }}</link>
                <description><![CDATA[{!! $post->body !!}]]></description>
                <category>{{ $post->category }}</category>
                <author><![CDATA[Hardk Savani]]></author>
                <guid>{{ $post->id }}</guid>
                <pubDate>{{ $post->created_at->toRssString() }}</pubDate>
            </item>
        @endforeach
    </channel>
</rss>

Ejecute la aplicación Laravel:

Se han realizado todos los pasos requeridos, ahora debe escribir el siguiente comando y presionar enter para ejecutar la aplicación Laravel:

php artisan serve

Ahora, vaya a su navegador web, escriba la URL dada y vea el resultado de la aplicación:

http://localhost:8000/feed

Espero que te pueda ayudar... 

Fuente: https://www.itsolutionstuff.com/post/laravel-9-create-rss-feed-example-tutorialexample.html

#laravel 

What is GEEK

Buddha Community

Cómo Agregar RSS Feed En Laravel 9
Seamus  Quitzon

Seamus Quitzon

1595201363

Php how to delete multiple rows through checkbox using ajax in laravel

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'name','description'
    ];
}

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.

routes/web.php

Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);

#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete

Juned Ghanchi

1621508419

Laravel App Development Company in India, Hire Laravel Developers

Hire our expert team of Laravel app developers for flexible PHP applications across various cloud service providers.

With this easy build technology, we develop feature-rich apps that make your complex business process a lot easier. Our apps are,

  • More secure and scalable.
  • A good framework lets you manage and organize resources better.
  • And have a rich community base.

Get your business a best in classlaravel app. Hire laravel app developers in India. We have the best organizational set-up to provide you the most advanced app development services.

#laravel app development company india #hire laravel developers india #laravel app development company #hire laravel developers #laravel development agency #laravel app programmers

Diego  Elizondo

Diego Elizondo

1656707640

Cómo Agregar RSS Feed En Laravel 9

RSS significa Really Simple Syndication y una fuente RSS es un archivo XML que tiene una lista de URL actualizadas de su sitio web. Puede utilizar la fuente RSS para el envío automático de actualizaciones de notificaciones por correo electrónico.

En este ejemplo, crearemos una tabla de publicaciones con título, slug y cuerpo. Luego crearemos una fábrica para publicaciones ficticias. Luego, generaremos un archivo XML y enumeraremos todas las URL para las publicaciones. Es un ejemplo muy básico. así que sigamos y obtendrá un archivo de mapa del sitio para su sitio web y lo enviará a la herramienta del webmaster.

Sigamos los pasos a continuación:

Paso 1: Instalar Laravel

Este paso no es obligatorio; sin embargo, si no ha creado la aplicación laravel, puede continuar y ejecutar el siguiente comando:

composer create-project laravel/laravel example-app

Paso 2: crear un modelo y una migración posterior

En este paso, crearemos la migración y el modelo. Entonces, ejecutemos el siguiente comando para crear una tabla de publicaciones.

php artisan make:migration create_posts_table

A continuación, simplemente actualice el código debajo del archivo de migración.

base de datos/migraciones/create_posts_table.php

<?php
  
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
  
return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('slug');
            $table->text('body');
            $table->timestamps();
        });
    }
  
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
};

Luego ejecute la nueva migración creada con el siguiente comando:

php artisan migrate

Ahora, ejecute el siguiente comando para crear el modelo Post.

php artisan make:model Post

Luego actualice el siguiente código al modelo Post.

aplicación/Modelos/Post.php

<?php
  
namespace App\Models;
  
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
  
class Post extends Model
{
    use HasFactory;
  
    protected $fillable = [
        'title', 'slug', 'body'
    ];
}

Paso 3: crear una fábrica de publicaciones

En este paso, crearemos la clase Post factory y generaremos registros ficticios usando el comando tinker. así que ejecutemos el siguiente comando para crear una fábrica posterior.

php artisan make:factory PostFactory

A continuación, copie el código siguiente y actualice el archivo PostFactory.php.

base de datos/fábricas/PostFactory.php

<?php
  
namespace Database\Factories;
  
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Post;
use Illuminate\Support\Str;
  
/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Post>
 */
class PostFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Post::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'title' => $this->faker->text(),
            'slug' => Str::slug($this->faker->text()),
            'body' => $this->faker->paragraph()
        ];
    }
}

Luego, simplemente ejecute el comando tinker y cree publicaciones ficticias.

php artisan tinker
App\Models\Post::factory()->count(30)->create();

Paso 4: Crear Ruta

En este paso, crearemos una ruta sitemap.xml. así que vamos a agregarlo.

rutas/web.php

<?php
  
use Illuminate\Support\Facades\Route;
  
use App\Http\Controllers\RSSFeedController;
   
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
    
Route::get('feed', [RSSFeedController::class, 'index']);

Paso 5: Crear controlador

En este paso, tenemos que crear un nuevo controlador como RSSFeedController con index(). obtendremos todas las publicaciones y las pasaremos al archivo blade. devolveremos la respuesta como un archivo xml. así que actualicemos el siguiente código:

app/Http/Controllers/RSSFeedController.php

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use App\Models\Post;
  
class RSSFeedController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $posts = Post::latest()->get();
  
        return response()->view('rss', [
            'posts' => $posts
        ])->header('Content-Type', 'text/xml');
    }
}

Paso 6: Crear archivo de vista

En el último paso, creemos rss.blade.php para mostrar todas las publicaciones y coloque el siguiente código:

recursos/vistas/rss.blade.php

<?=
'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
?>
<rss version="2.0">
    <channel>
        <title><![CDATA[ ]]></title>
        <link><![CDATA[ https://your-website.com/feed ]]></link>
        <description><![CDATA[ Your website description ]]></description>
        <language>en</language>
        <pubDate>{{ now() }}</pubDate>
  
        @foreach($posts as $post)
            <item>
                <title><![CDATA[{{ $post->title }}]]></title>
                <link>{{ $post->slug }}</link>
                <description><![CDATA[{!! $post->body !!}]]></description>
                <category>{{ $post->category }}</category>
                <author><![CDATA[Hardk Savani]]></author>
                <guid>{{ $post->id }}</guid>
                <pubDate>{{ $post->created_at->toRssString() }}</pubDate>
            </item>
        @endforeach
    </channel>
</rss>

Ejecute la aplicación Laravel:

Se han realizado todos los pasos requeridos, ahora debe escribir el siguiente comando y presionar enter para ejecutar la aplicación Laravel:

php artisan serve

Ahora, vaya a su navegador web, escriba la URL dada y vea el resultado de la aplicación:

http://localhost:8000/feed

Espero que te pueda ayudar... 

Fuente: https://www.itsolutionstuff.com/post/laravel-9-create-rss-feed-example-tutorialexample.html

#laravel 

Liz  Fernandes

Liz Fernandes

1670234150

Best Laravel Development Company

In the present world, PHP is a well-liked framework. Laravel is one of the most well-known frameworks out there. The popularity of Laravel is due to its expressiveness, flexibility, good controllers, strength, seamless caching, and time savings when handling tasks like routing, authentication, sessions, and many more.

Laravel is a PHP framework that everyone who knows PHP should be familiar with. The Laravel PHP framework is simple to learn and use, but it is packed with useful features. Despite rising market competition, many developers consider Laravel to be one of the best PHP frameworks available.

WPWeb Infotech is a top Laravel development company in India and the US since 2015. They develop reliable, scalable Laravel web and mobile apps using Ajax-enabled widgets, MVC patterns, and built-in tools. WPWeb Infotech has top-notch expertise in combining a variety of front- and back-end technologies like Laravel + VueJS, Laravel + Angular, and Laravel + ReactJS to create scalable and secure web architectures, so you don't have to worry about scalability and flexibility while developing your product. They understand business scale and recommend technology that fits. Agile experts reduce web and mobile app development time and risk.

When it comes to hiring Laravel developers from India, they are the best choice because their Laravel developers can work according to your time zone to provide you with hassle-free, innovative, and straightforward web development solutions. Being the most trusted Laravel development company in India, they can help you reach new heights of success, unleashing the power of the Laravel PHP framework.

Partner with one of India’s best Laravel Development Company and get the most expertise in Laravel development.

#laravel  #laravel-development #laravel-development-company #laravel-development-services #hire-laravel-developers

sophia tondon

sophia tondon

1618970788

Top Laravel Development Company India | Laravel Development Services

Laravel is a popular framework for website development, acquiring 25.85% of the PHP framework market share. As a most admired framework among PHP frameworks, it is being utilized for e-commerce, enterprise, social media, and various different types of websites.

There are more than 1 million websites worldwide available over the web that are created using Laravel. Laravel framework is the first preference of PHP developers as it allows them to develop highly scalable, flexible, and faster web applications.

Surely, you, too, would want to deliver a splendid and unhindered user experience to your target audience over the web. Laravel framework can help you achieve this pursuit at ease; all you need to do is hire Laravel developers from reliable & coveted hosts. But! There is no shortage of Laravel development companies that promise to deliver an excellent solution, but only some are able to deliver top-notch quality.

Therefore, I have decided to enlist top Laravel development companies to help you find a reliable and expert host for web development. So, stay hooked with me till the end of this article and explore the best Laravel developers in 2021.

While creating this list, I have kept the following pointers in reflection:

Years of excellence (average 8 years)
Workfolio
Rewards & Recognition
Client rating & feedback
Hourly/Monthly Price
Number of happy clients
Number of successfully launched projects
Minimum man-years experience
So, let’s not waste a minute and glance at top Laravel development companies to hire for creating excellent web solutions.

Read More - https://www.valuecoders.com/blog/technology-and-apps/top-laravel-development-companies-to-hire-experts/

#hire a laravel developer #hire laravel developer #hire laravel developers #laravel developer for hire #laravel developers #laravel developers for hire