<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Baitulhassan Shaikh</title>
    <description>The latest articles on DEV Community by Baitulhassan Shaikh (@baitulhassanshaikh).</description>
    <link>https://dev.to/baitulhassanshaikh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4249658%2Fd77d895f-615c-448c-9611-cb063a69a5ab.png</url>
      <title>DEV Community: Baitulhassan Shaikh</title>
      <link>https://dev.to/baitulhassanshaikh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/baitulhassanshaikh"/>
    <language>en</language>
    <item>
      <title>How to Integrate Gemini AI into a Laravel Application for Smart Web Features</title>
      <dc:creator>Baitulhassan Shaikh</dc:creator>
      <pubDate>Tue, 17 Nov 2026 15:36:25 +0000</pubDate>
      <link>https://dev.to/baitulhassanshaikh/how-to-integrate-gemini-ai-into-a-laravel-application-for-smart-web-features-4l2e</link>
      <guid>https://dev.to/baitulhassanshaikh/how-to-integrate-gemini-ai-into-a-laravel-application-for-smart-web-features-4l2e</guid>
      <description>&lt;p&gt;Artificial Intelligence is transforming modern web applications. In this quick guide, we will look at how to easily integrate "Gemini AI" into a "Laravel" application to build smart, automated features like text generation, chatbots, and content assistants.&lt;/p&gt;




&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;PHP 8.2+ &amp;amp; Composer installed&lt;/li&gt;
&lt;li&gt;A running Laravel project&lt;/li&gt;
&lt;li&gt;A Gemini API Key from Google AI Studio&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 1: Install the Google Generative AI Package via Composer
&lt;/h3&gt;

&lt;p&gt;Run the following command in your terminal to install the official or community PHP client for Gemini API:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
composer require google/generative-ai-php&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;br&gt;
(Note: You can also use Laravel's native HTTP client to call the Gemini REST API directly if preferred).&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2: Configure Your API Key
&lt;/h3&gt;

&lt;p&gt;Add your Gemini API key to your &lt;code&gt;.env\&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;env&lt;br&gt;
GEMINI_API_KEY=your_actual_api_key_here&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, add a configuration entry in &lt;code&gt;config/services.php\&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;php&lt;br&gt;
'gemini' =&amp;gt; [&lt;br&gt;
    'api_key' =&amp;gt; env('GEMINI_API_KEY'),&lt;br&gt;
],&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3: Create a Controller to Handle AI Requests
&lt;/h3&gt;

&lt;p&gt;Run the artisan command to create a controller:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
php artisan make:controller AIController&lt;br&gt;
\&lt;/code&gt;&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Inside your controller, write a method to send prompts to Gemini and return the response:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;`php&lt;br&gt;
namespace App\Http\Controllers;&lt;/p&gt;

&lt;p&gt;use Illuminate\Http\Request;&lt;br&gt;
use Illuminate\Support\Facades\Http;&lt;/p&gt;

&lt;p&gt;class AIController extends Controller&lt;br&gt;
{&lt;br&gt;
    public function generateResponse(Request $request)&lt;br&gt;
    {&lt;br&gt;
        $prompt = $request-&amp;gt;input('prompt');&lt;br&gt;
        $apiKey = config('services.gemini.api_key');&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $response = Http::post("https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={$apiKey}", [
        'contents' =&amp;gt; [
            [
                'parts' =&amp;gt; [
                    ['text' =&amp;gt; $prompt]
                ]
            ]
        ]
    ]);

    return response()-&amp;gt;json($response-&amp;gt;json());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
`&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;By integrating Gemini AI into Laravel, you can elevate standard web apps into intelligent platforms. &lt;/p&gt;




&lt;p&gt;&lt;em&gt;Written by **Baitulhassan Shaikh&lt;/em&gt;&lt;em&gt;, Founder &amp;amp; Full-Stack Developer at **ALFAIZ Web Agency&lt;/em&gt;&lt;em&gt;. Specializing in custom Laravel apps, secure backend architectures, and AI-powered web solutions.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>ai</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
