#laravel facade tutorial
Explore tagged Tumblr posts
devrohitsblog · 1 year ago
Text
How to Create Custom Facade in laravel?
A facade is a design pattern that provides a static interface to classes inside the framework's service container. we are creating a custom facade in laravel
0 notes
jeetutech · 2 years ago
Text
Best way to Check Table Existence in the Database Laravel?
in this tutorial learn how to checking table exists in database or not, I have guide step by step how to check table exists in your database. In Laravel, there are multiple ways to check if a database table exists. I’ll provide you with a few different methods you can use: Total method 1.Schema Builder’s hasTable method: 2.Using the DB facade: 3.Using the connection…
View On WordPress
0 notes
decodewebin · 6 years ago
Text
A comprehensive guide on laravel facades for absolute beginners.
Tumblr media
5 notes · View notes
laravelvuejs · 6 years ago
Text
Laravel Beginner tutorial | Laravel Facade - simplest explanation - Laravel
Laravel Beginner tutorial | Laravel Facade – simplest explanation – Laravel
Laravel Beginner tutorial | Laravel Facade – simplest explanation – Laravel
[ad_1]
Simplest Explanation of Laravel Facades. Implement your own Facade. What is Laravel Facades.
Full course at https://bitfumes.com/courses/laravel/laravel-for-beginner-from-download-to-deploy
Check https://bitfumes.com For ads free and more advanced courses (use Coupon code WELCOME60 to get 60% discount)
Join Our…
View On WordPress
0 notes
codesolutionsstuff · 3 years ago
Text
Social Media Share Buttons Integration Tutorial in Laravel 9
Tumblr media
In this short tutorial, we'll show you how to use the insanely helpful jorenvanhocht/laravel-share package to add social media share buttons to every page of a Laravel application. The quality of your site's material is widely spread via social share icons, which are incredibly beneficial in spreading your information to a bigger audience. The social sharing option increases the likelihood that your material will receive free advertising. These buttons, which are put to every page of your website, offer a powerful way to let site visitors know about the most helpful content on your website. You better know how to incorporate the social media share button in the Laravel project if you're a Laravel developer. We will use the jorenvanhocht/laravel-share package to make this process tutorial simple, and you can obtain this package using the Composer tool so that you won't have to create it from scratch. The jorenvanhocht/laravel-share package is absolutely necessary for this Laravel8 social media share button example. It is a library built on PHP that enables you to create different social share links. You can build social share links for Facebook, Twitter, Linkedin, WhatsApp, Reddit, and Telegram after adding this package into your project.
Table of Contents
- Download Laravel App - Add Laravel Share Package - Register Laravel Share - Set Up New Controller - Create Route - Add Social Media Share Buttons in View - Start Application
Download Laravel App
Create a new Laravel app to get started; use the given command; you may alter the project name if you'd like. composer create-project --prefer-dist laravel/laravel laravel-demo cd laravel-demo
Add Laravel Share Package
To begin installing the Laravel sharing library, open the console window in your view, type the suggested command, and then press Enter. composer require jorenvanhocht/laravel-share
Register Laravel Share
Make sure to register the ServiceProvider and the facade, respectively, in the config/app.php file to fully utilize the package. Read the full article
0 notes
shotsloading167 · 4 years ago
Text
Phpstorm Xdebug Laravel
Tumblr media
Phpstorm Xdebug Laravel Tutorial
Phpstorm Xdebug Laravel Artisan Serve
Xdebug Phpstorm Cli
Integrate Xdebug with the PHP interpreter Open the active php.ini file in the editor: In the Settings/Preferences dialog Ctrl+Alt+S, click PHP. On the PHP page that opens, click next to the CLI Interpreter field. I have a AngularJS + Laravel application and not able to setup debugging. On project root folder I have a PHP file and the debugger breaks at this file always. I use PHPStorm and have unchecked the '.
Features
Lots of PHP developers create their applications using Laravel, a free, open source PHP web application framework. It is built on top of several Symfony components, and provides a development framework that makes common tasks such as authentication, routing, sessions and caching much easier to implement.
Last summer, we introduced support for Blade, the template language used by Laravel. Recoverit download mac. Support for artisan, the command line tool for Laravel developers, is baked into PhpStorm as well. Using the Laravel plugin and the Laravel IDE helper, we can further extend PhpStorm’s support for Laravel applications. Let’s see how!
The Laravel IDE Helper
After making sure Composer is available for use in our project, we can install the Laravel IDE helper into our project using the Composer | Add dependency… context menu. We can search for barryvdh/laravel-ide-helper and click Install to download the package and add it to our project.
After registering the ‘BarryvdhLaravelIdeHelperIdeHelperServiceProvider’service provider in our application and running artisan ide-helper:generate, PhpStorm will have code completion support and syntax highlighting for many of Laravel’s facades.
The Laravel Plugin for PhpStorm
To further enhance the Laravel experience, we can also install the Laravel Plugin. Under Settings (Preferences) | Plugins, click the Browse repositories… button and search for Laravel. The Install plugin button will download and install the plugin into our IDE.
Restart the IDE and enable the plugin under Settings (Preferences) | Other Settings | Laravel Plugin | Enable Plugin for this Project. All of a sudden, PhpStorm will know what all Laravel facades do, and provide code completion for controllers, views, routes, configuration, translations and many other things!
There’s not only code completion… We can navigate to these items as well! Using Ctrl+Click (CMD+Click on Mac OS X) or Go To Declaration (Ctrl+B / CMD+B), PhpStorm will navigate us to where, for example, a configuration entry is declared.
Working in Blade templates? The Laravel plugin also enhances that experience, for example with code completion for @section directives.
Anxious to learn more? Check our Laravel tutorial, which covers getting PhpStorm ready for Laravel development, code completion, navigation, automatic code inspections, command line tool support, debugging and unit testing!
Are you a Laravel developer? Give PhpStorm 8 a try! We have an elaborate tutorial on Laravel support in PhpStorm which will help you get the most out of our IDE. Your feedback is very welcome through the issue tracker, by posting in the comments below, or in our forums!
Develop with pleasure! – JetBrains PhpStorm Team
Stef Rouschop
min read
TLDR;
This guide will make you install Xdebug on your Mac without the performance downsides, but still being able to use all the Xdebug goodnesses. Most Xdebug setups only allow you to use it through a web browser plugin. This is not helpful when you’re following a TDD approach. So we’ll get it to work right from your tests in PhpStorm, no browser needed!
Having tests is awesome!
I’m a huge fan of tests in Laravel and try to develop as much as possible using the TDD approach. When a project grows over the years, your tests are becoming like a guard that will tell when you messed up functionality by adding or changing some code later on. This gives a peace of mind and has saved my bacon many times already.
PhpStorm has a great GUI for running PHPUnit tests where you’re able to click directly on the links to the scripts where a test fails. I love this workflow and I’ve never used phpunit on the command line since. Praat phonetics. However, when your tests fail, it can become somewhat cumbersome to figure out what is going on. The first thing I always do is add ->dump() to the request, that will point me in the right direction most of the time. But there are cases where you really need to dig into the code. This is where I previously placed some dd() in the code and then tried to follow the steps. Raise your hand if you’ve been there 🤚!
Xdebug is a wonderful tool that can help you with that, but I previously used it a long time ago with a browser plugin. Since PHPUnit gets really slow when Xdebug is installed and it also impacts the composer performance, I removed it from my system and never used it since. Until I recently discovered “on-demand Xdebug” in PhpStorm! This will not enable Xdebug by default, and will only use it when you need to.It’s really simple to set up and I love using it! You can also use it directly in your tests, so you don’t have to recreate the situation in your browser. I’ll show you how to install and use it in this article.
Install
In our company we only use Mac’s, I have no idea how to set this up on Windows, so you’ll have to google around if that’s your case. For Linux, it will more or less be the same (except for PHP installation) I think.
I’m assuming you’ve been using Homebrew to install the latest version of PHP. It’s as simple as brew install php.
Extensions as Xdebug have recently been removed from Homebrew and need to be installed using PECL. Luckily that is also really easy!pecl install xdebugThe install will add a reference to Xdebug in your php.ini file so it will be loaded by default. We don’t want that! So we’ll remove this reference. Here’s how to do it:On your command line enter: php --ini this will give you the path of the php.ini file that is used on your system.
Open the file in an editor of your choice, or use the default editor for this filetype. In the case of our example, we can do this with the command open /usr/local/etc/php/7.2/php.ini. This will open the php.ini file. We can see the reference added by the Xdebug installer on line 1: zend_extension=”xdebug.so”. We need to remove this line so Xdebug is not loaded by default anymore. Twitch deere. There, all done 🥳!
Tumblr media
PhpStorm setup
I’ll assume you have a setup for your TDD workflow in PhpStorm. The purpose of this guide is only to extend it with Xdebug. If you don’t have it, here is an old but still relevant video from Laracasts.com: Be Awesome in PHPStorm: Testing in PHPStorm.
We will need to tell PhpStorm where Xdebug is located for using it on demand. In the settings navigate to Languages and Frameworks and then PHP. On the CLI Interpreter click on the … button like in the screenshot.
Now we can specify where Xdebug is located on your system. In our example this is in /usr/local/lib/php/pecl/20170718/xdebug.so, but this path depends on the version and can be different on your system. So be sure to click on the folder icon to navigate through your system and find it.
When the path is correct and you hit the refresh button, you will see the Xdebug version that was found by PhpStorm.
Using it
Phpstorm Xdebug Laravel Tutorial
For sake of simplicity, we’ll create a simple test where we assert the content of two routes. The routes we’re about to test will just return some variables, nothing fancy going on here, you’ll get the idea. Laravel makes creating tests really easy with the artisan helper php artisan make:test TwoRoutesTest.
In the image below you can see how the tests are run when you’ll hit the green “play” button, nothing new here. Did you also know about the SHIFT + CTRL + R shortcut? Place your cursor in a test and hit the shortcut and only this single test will run. When you place the cursor outside of a test, all the tests of this test-file will run. I really love this shortcut 😍!
Now, let's use Xdebug!
Phpstorm Xdebug Laravel Artisan Serve
Go to your code and place some breakpoints on the left side of the lines. They will be marked with red circles when you click them. This time, don’t click the green “play” button, but the red bug on the right side of it.
Xdebug Phpstorm Cli
The test will stop on the first breakpoint. You’ll get a nice overview of all (global) variables in the debug screen. When you press the green “play / pause” button on the left side of the screen you’ll go to the next breakpoint. You can really dig in the code now to figure out where your bugs happen. I won’t go into detail about all the PhpStorm/Xdebug functionality. That might be a completely different blog post.
Happy debugging
I hope this will enhance your debugging workflow as much as it did for me!
Tumblr media
0 notes
surfsidemedia · 5 years ago
Video
youtube
0 notes
nehanguyen · 5 years ago
Text
Laravel 7 Tutorial for beginner - Raw SQL Queries
Laravel 7 Tutorial for beginner – Raw SQL Queries
Running Raw SQL Queries in Laravel 7 for beginner basics series. Using DB facade to run Raw SQL Queries in Laravel 7
source https://morioh.com/p/3e6cb9e20139
View On WordPress
0 notes
itsmetacentric · 5 years ago
Link
laravel create facade,laravel 5 8 create facade,laravel 6 create facade,laravel use facade in blade,laravel 5 create facade example,laravel create custom facade tutorial,How to create facade in laravel 6
0 notes
airman7com · 6 years ago
Text
laravel - Get All Table Name
laravel – Get All Table Name
Disini saya akan membagikan tutorial fetch tables list dari database dengan menggunakan DB facade.
Untuk mendapatkan list nama table kita dapat menggunakan sql query “SHOW TABLES”.
Example:
$tables = \DB::select('SHOW TABLES'); $tables = array_map('current',$tables); dd($tables);
Output:
Array ( [0] => ban [1] => events [2] => log_activities [3] => migrations [4] => password_resets [5] =>…
View On WordPress
0 notes
viralleakszone-blog · 6 years ago
Text
Yii Tutorial
http://www.viralleakszone.com/yii-tutorial/
Yii Tutorial
Yii Tutorial
Yii Tutorial for Beginners - Learn Yii in simple and easy steps starting from basic 
to advanced concepts with examples including Overview, Installation, Create Page, 
Application Structure, Entry Scripts, Controllers, Using Controllers, Using Actions,
 Models, Widgets, Modules, Views, Layouts, Assets, Asset Conversion, Extensions, 
Creating Extensions, HTTP Requests, Responses, URL Formats, URL Routing, Rules of 
URL, HTML Forms, Ad Hoc and AJAX Validations, Sessions, Using Flash Data, Cookies, 
Using Cookies, Files Upload, Formatting, Pagination, Sorting, Properties, 
Data Providers, Data Widgets, ListView Widgets, GridView Widgets, Events, 
Creating Event, Behaviors, Creating a Behavior, Configurations, Dependency 
Injection, Database Access, Data Access Objects, Query Builder, Active Record, 
Database Migration, Theming, RESTful APIs, RESTful APIs in Action, Fields, 
Testing, Caching, Fragment Caching, Aliases, Logging, Error Handling, 
Authentication, Authorization, Localization, Gii, Creating a Model, Generating 
Controller and Module.
Laravel
Laravel Tutorial
Laravel is a powerful MVC PHP framework, designed for developers who need a simple and elegant toolk
Laravel – Overview
IntroductionLaravel is an open-source PHP framework, which is robust and easy to understand. It foll
Laravel – Installation
For managing dependencies, Laravel uses composer. Make sure you have a Composer installed on yo
Laravel – Application Structure
The application structure in Laravel is basically the structure of folders, sub-folders and files in
Laravel – Configuration
In the previous chapter, we have seen that the basic configuration files of Laravel are included in
Laravel – Routing
In Laravel, all requests are mapped with the help of routes. Basic routing routes the request to the
Laravel – Middleware
Middleware acts as a bridge between a request and a response. It is a type of filtering mechanism. T
Laravel – Namespaces
Namespaces are used in various programming languages to create a separate group of variable, functio
Laravel – Controllers
In the MVC framework, the letter ‘C’ stands for Controller. It acts as a directing traffic between V
Laravel – Request
In this chapter, you will learn in detail about Requests in Laravel.Retrieving the Request URIThe&nb
Laravel – Cookie
Cookies play an important role while dealing a user’s session on a web application. In this chapter,
Laravel – Response
A web application responds to a user’s request in many ways depending on many parameters. This chapt
Laravel – Views
In MVC framework, the letter V stands for Views. It separates the application logic a
Laravel – Blade Templates
Laravel 5.1 introduces the concept of using Blade, a templating engine to design a unique layou
Laravel – Redirections
Named route is used to give specific name to a route. The name can be assigned using the as&nbs
Laravel – Working With Database
Laravel has made processing with database very easy. Laravel currently supports following 4 database
Laravel – Errors and Logging
This chapter deals with errors and logging in Laravel projects and how to work on them.ErrorsA proje
Laravel – Forms
Laravel provides various in built tags to handle HTML forms easily and securely. All the major eleme
Laravel – Localization
Localization feature of Laravel supports different language to be used in application. You need to s
Laravel – Session
Sessions are used to store information about the user across the requests. Laravel provides various
Laravel – Validation
Validation is the most important aspect while designing an application. It validates the incoming da
Laravel – File Uploading
Uploading Files in Laravel is very easy. All we need to do is to create a view file where a user can
Laravel – Sending Email
Laravel uses free feature-rich library SwiftMailer to send emails. Using the library funct
Laravel – Ajax
Ajax (Asynchronous JavaScript and XML) is a set of web development techniques utilizing many we
Laravel – Error Handling
Most web applications have specific mechanisms for error handling. Using these, they track errors an
Laravel – Event Handling
Events provide a simple observer implementation which allows a user to subscribe and listen to vario
Laravel – Facades
Facades provide a static interface to classes that are available in the application’s serv
Laravel – Contracts
Laravel contracts are a set of interfaces with various functionalities and core services provided by
Laravel – CSRF Protection
CSRF refers to Cross Site Forgery attacks on web applications. CSRF attacks are the unauthorized act
Laravel – Authentication
Authentication is the process of identifying the user credentials. In web applications, authenticati
Laravel – Authorization
In the previous chapter, we have studied about authentication process in Laravel. This chapter expla
Laravel – Artisan Console
Laravel framework provides three primary tools for interaction through command-line namely: Art
Laravel – Encryption
Encryption is a process of converting a plain text to a message using some algorithms such that any
Laravel – Hashing
Hashing is the process of transforming a string of characters into a shorter fixed value or a key th
Laravel – Understanding Release Process
Every web application framework has its own version history and it is always being updated and maint
Laravel – Useful Resources
The following resources contain additional information on Laravel. Please use them to get more in-de
Discuss Laravel
Laravel is a powerful MVC PHP framework, designed for developers who need a simple and elegant toolk
Laravel Security
Security is important feature while designing web applications. It assures the users of the websit
0 notes
laravelvuejs · 8 years ago
Text
Laravel 5.5 Facades Tutorial Example From Scratch
[ad_1]
Laravel 5.5 Facades Tutorial is today’s leading topic. Facades provide a “static” interface to classes that are available in the application’s service container. Laravel ships with so many facades which provide access to almost all of the Laravel’s features. Laravel facade serves as “static proxies” to underlying classes in the service container. All of Laravel’s facades are defined in…
View On WordPress
2 notes · View notes
myfreecourses · 7 years ago
Text
Laravel 5.6 masterclass - very comprehensive - 125 videos - Udemy
Laravel 5.6 masterclass – very comprehensive – 125 videos – Udemy
Laravel 5.6 masterclass – very comprehensive – 125 videos – Udemy
This tutorial touches all aspects of laravel comprehensively and extensively. Best tutorial on this topic.
What Will I Learn?
  Basics of Laravel
Learn Laravel Installation
Laravel Environment Setup and Configuration
Laravel Directory Structure
Understand Request Lifecycle in Laravel
Understand Service Providers, Facades and…
View On WordPress
0 notes
mbaljeetsingh · 8 years ago
Text
Uploading Images to Cloudinary with Laravel (sponsor)
Sponsor / November 13, 2017
Uploading Images to Cloudinary with Laravel (sponsor)
Images are an essential part of any web application. They have the power to create an emotional response in the audience, which is worth its weight in gold. Our brain is designed to interpret images much quicker than text, so when developing a website, it is imperative to take your images seriously.
In this tutorial, I will introduce you to image services offered by Cloudinary for uploading images in Laravel. We will focus on uploading images to the Cloudinary server in Laravel application.
Cloudinary is the end-to-end image and video management solution, which also offers robust, highly reliable cloud storage for all your media.
What We will Build
In this tutorial, we will upload images to Cloudinary using jrm2k6/cloudder package. This package will do the heavy lifting for us and make it easy to interact with Cloudinary API.
Sign up For a Free Cloudinary Account
Before we start installing Laravel, go to Cloudinary and sign up for a free Cloudinary account.
This will give you the necessary credentials to access and interact with Cloudinary functionalities. Once you have signed up, log in and view your dashboard. It should be similar to this:
Take note of your account details Cloud name, API Key, API Secret because you will need them within your .env file:
CLOUDINARY_API_KEY = 'Your key' CLOUDINARY_API_SECRET = 'Your secret' CLOUDINARY_CLOUD_NAME = 'Your cloud name'
You are almost ready to start utilizing some of the amazing services and functionalities offered by Cloudinary.
Install Laravel
Laravel utilizes Composer to manage its dependencies. So before using Laravel, make sure you have Composer installed on your machine.
You can download and install Laravel via:
Laravel installer
Composer create-project.
For the sake of this tutorial, let’s proceed by using the second option. So run :
composer create-project --prefer-dist laravel/laravel laravel-upload-tut
This will create a Laravel project called laravel-upload-tut in your development directory.
Next, install jrm2k6/cloudder package using composer:
composer require jrm2k6/cloudder:0.4.*
Now open config\app.php file and add the following service provider and aliases in respective array:
'providers' => array( 'JD\Cloudder\CloudderServiceProvider' ); 'aliases' => array( 'Cloudder' => 'JD\Cloudder\Facades\Cloudder' );
Run the following command to publish:
php artisan vendor:publish --provider="JD\Cloudder\CloudderServiceProvider"
The command above will generate a cloudder configuration file for you in the following path config/cloudder.php
You can change the following settings (optional) with corresponding values from your dashboard:
CLOUDINARY_BASE_URL CLOUDINARY_SECURE_URL CLOUDINARY_API_BASE_URL
Start the PHP’s built-in development server to serve your application:
php artisan serve
Creating a Controller and Route
We are getting close; the next thing is to create a controller that will handle the image upload request:
php artisan make:controller ImageUploadController
Open app\Http\Controllers and add :
<?php namespace App\Http\Controllers; use JD\Cloudder\Facades\Cloudder; use Illuminate\Http\Request; class ImageUploadController extends Controller { public function home() { return view('home'); } }
This function will render the view for uploading our images. We will create this view in a bit. To handle image upload, let’s add another function uploadImages()
<?php ... class ImageUploadController extends Controller { public function home() { ... } public function uploadImages(Request $request) { $this->validate($request,[ 'image_name'=>'required|mimes:jpeg,bmp,jpg,png|between:1, 6000', ]); $image_name = $request->file('image_name')->getRealPath();; Cloudder::upload($image_name, null); return redirect()->back()->with('status', 'Image Uploaded Successfully'); } }
Here, we handled validation of an uploaded image and ensured that the file size is between 1kb and 6000kb. Then we used Cloudder::upload($image_name, null) to handle the actual upload of the image to Cloudinary account.
For the upload routes, open routes/web.php file and add the following:
<?php Route::get('/', 'ImageUploadController@home'); Route::post('/upload/images', [ 'uses' => 'ImageUploadController@uploadImages', 'as' => 'uploadImage' ]);
The next thing to do is to create a view file for our example application. So head over to resources/views and create home.blade.php file. Fill it with :
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width"> <title>Cloudinary Image Upload</title> <meta name="description" content="Prego is a project management app built for learning purposes"> <link rel="stylesheet" href="http://ift.tt/2apRjw3"> <link rel="stylesheet" href=""> </head> <body> <div class="container" style="margin-top: 100px;"> <div class="row"> <h4 class="text-center"> Upload Images </h4> <div class="row"> <div id="formWrapper" class="col-md-4 col-md-offset-4"> <form class="form-vertical" role="form" enctype="multipart/form-data" method="post" action=""> @if(session()->has('status')) <div class="alert alert-info" role="alert"> </div> @endif <div class="form-group"> <input type="file" name="image_name" class="form-control" id="name" value=""> @if($errors->has('image_name')) <span class="help-block"></span> @endif </div> <div class="form-group"> <button type="submit" class="btn btn-success">Upload Image </button> </div> </form> </div> </div> </div> </div> </body> </html>
To spice our page up a little, let’s add navigation:
<!DOCTYPE html> <html> <head> ... </head> <body> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Cloudinary Image Upload</a> </div> </div> </nav> ... </body> </html>
You will notice that we included a stylesheet in the home.blade.php file. Let’s now create public/css/style.css and add:
#formWrapper { border: 2px solid #f5f5f5; padding: 20px; }
By now, your page should look similar to this:
You can go ahead and upload any image now.
There you have it, uploading images to Cloudinary from the Laravel application is as simple as that.
##Bonus: Persisting Image Delivery URLs
The objective of this tutorial was to show you how to upload images to Cloudinary using Laravel. We have been able to achieve this already, but you might want to save the URL of the uploaded image in your database and be able to view all of them, as well.
Let’s create a model for this purpose. The fastest way to create a model is to use the following command, with a parameter that you can use to specify the model name. So in our case, we will create an Upload model.
php artisan make:model Upload -m
Once you are done, you will find a new file as app/Upload.php and migration file associated with the model for our database schema.
Now open the migration file generated and edit it to reflect our database schema:
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateUploadsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('uploads', function (Blueprint $table) { $table->increments('id'); $table->string('image_name'); $table->string('image_url'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('uploads'); } }
##Database Set Up Open the .env file and add your database details
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=Your-database-name DB_USERNAME=Your-database-username DB_PASSWORD=Your-database-password
##Migrating and Creating Table You can go ahead and run the migration with:
php artisan migrate
If you hit the following error when trying to run the migration command, it’s because you are running an older version of MySQL:
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
You can read more about it here. But a quick fix is to drop the database and re-create it. Then you have to edit your AppServiceProvider.php file and set a default string length inside the boot method:
use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }
You can now run the migration command again and everything should be fine.
In order to obtain and save the image URL uploaded to Cloudinary, we will need to edit the logic within ImageUploadController. So can go ahead and replace uploadImages() function with this:
public function uploadImages(Request $request) { $this->validate($request,[ 'image_name'=>'required|mimes:jpeg,bmp,jpg,png|between:1, 6000', ]); $image = $request->file('image_name'); $name = $request->file('image_name')->getClientOriginalName(); $image_name = $request->file('image_name')->getRealPath();; Cloudder::upload($image_name, null); list($width, $height) = getimagesize($image_name); $image_url= Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height"=>$height]); //save to uploads directory $image->move(public_path("uploads"), $name); //Save images $this->saveImages($request, $image_url); return redirect()->back()->with('status', 'Image Uploaded Successfully'); }
And add this new method to persist the image URL and name into the database:
public function saveImages(Request $request, $image_url) { $image = new Upload(); $image->image_name = $request->file('image_name')->getClientOriginalName(); $image->image_url = $image_url; $image->save(); }
To access the uploaded image on the homepage, we need to pass the image object to the view:
<?php namespace App\Http\Controllers; use App\Upload; ... class ImageUploadController extends Controller { public function home() { // add this $images = Upload::all(); return view('home', compact('images')); } }
To display the images, we also will need to edit the home.blade.php file:
<!DOCTYPE html> <html> <head> ... </head> <body> ... <div class="row" id="displayImages"> @if($images) @foreach($images as $image) <div class="col-md-3"> <a href="" target="_blank"> <img src="" class="img-responsive" alt=""> </a> </div> @endforeach @endif </div> </div> </div> </body> </html>
So we checked if the $images object is found within the view and loop through it to display the uploaded image.
And add this to the style.css file:
#displayImages { margin: 30px 0; }
You will see the images being displayed immediately after it has been uploaded successfully to Cloudinary:
Conclusion
Cloudinary is a reliable source for storage when it comes to images in particular and any other media files in general. As shown in this tutorial, uploading images to the Cloudinary server from your Laravel web application is so simple to achieve. You can check out Cloudinary for more information on how to manipulate your images dynamically to fit any design.
Many thanks to Cloudinary for sponsoring Laravel News this week.
via Laravel News http://ift.tt/2AACDDV
0 notes
t-baba · 8 years ago
Photo
Tumblr media
Hello, Laravel? Communicating with PHP through Phone Calls!
Twilio is a SaaS application which enables developers to build telephone applications using web technologies. In this two-part series, we will leverage Twilio to build a weather forecast app that is accessed using the telephone system. The backend will be written with the Laravel framework (an exploratory video course is available for purchase here, or in the form of written tutorials here).
In this part, we will create a simple program that will allow a user to call a phone number that we buy from Twilio, enter a zipcode, and receive the current weather forecast. The user can also get the weather for any day of the week via the voice menu prompts. In the second part of this series, we will leverage what was built in this article to allow the user to interact with the app via SMS (text message).
Prerequisites
Development Environment
This article assumes Homestead Improved is installed. It is not necessary to use it, but the commands might differ slightly if you use a different environment. If you are not familiar with Homestead and want to produce similar results as this article aims to produce, please visit this SitePoint article that shows how to set up Homestead, and if you need a crash course in Vagrant, please see this post. Additionally, if this whets your appetite and you feel like exploring PHP development environments in depth, we have a book about that available for purchase.
Dependencies
We will create a new Laravel project and then add the Twilio PHP SDK and Guzzle HTTP client library to the project:
cd ~/Code composer create-project --prefer-dist laravel/laravel Laravel 5.4.* cd Laravel composer require "twilio/sdk:^5.7" composer require "guzzlehttp/guzzle:~6.0"
Development
Let's go through all the steps, one by one.
Routes
Open up the routes/web.php file and add the following ones:
Route::group(['prefix' => 'voice', 'middleware' => 'twilio'], function () { Route::post('enterZipcode', 'VoiceController@showEnterZipcode')->name('enter-zip'); Route::post('zipcodeWeather', 'VoiceController@showZipcodeWeather')->name('zip-weather'); Route::post('dayWeather', 'VoiceController@showDayWeather')->name('day-weather'); Route::post('credits', 'VoiceController@showCredits')->name('credits'); });
In this app, all requests will be under the /voice path. When Twilio first connects to the app, it will go to /voice/enterZipcode via HTTP POST. Depending on what happens in the telephone call, Twilio will make requests to other endpoints. This includes /voice/zipcodeWeather for providing today's forecast, /voice/dayWeather, for providing a particular day's forecast, and /voice/credits for providing information on where the data came from.
Service Layer
We are going to add a service class. This class will hold a lot of the business logic that will be shared between the voice telephone app and the SMS app.
Create a new sub-folder called Services inside the app folder. Then, create a file called WeatherService.php and put the following content into it:
<?php namespace App\Services; use Illuminate\Support\Facades\Cache; use Twilio\Twiml; class WeatherService { }
This is a large file in the project, so we will build it piece by piece. Put the following pieces of code in this section inside our new service class:
public $daysOfWeek = [ 'Today', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ];
We will use this array to map a day of the week to a number; Sunday = 1, Monday = 2, etc.
public function getWeather($zip, $dayName) { $point = $this->getPoint($zip); $tz = $this->getTimeZone($point); $forecast = $this->retrieveNwsData($zip); $ts = $this->getTimestamp($dayName, $zip); $tzObj = new \DateTimeZone($tz->timezoneId); $tsObj = new \DateTime(null, $tzObj); $tsObj->setTimestamp($ts); foreach ($forecast->properties->periods as $k => $period) { $startTs = strtotime($period->startTime); $endTs = strtotime($period->endTime); if ($ts > $startTs and $ts < $endTs) { $day = $period; break; } } $response = new Twiml(); $weather = $day->name; $weather .= ' the ' . $tsObj->format('jS') . ': '; $weather .= $day->detailedForecast; $gather = $response->gather( [ 'numDigits' => 1, 'action' => route('day-weather', [], false) ] ); $menuText = ' '; $menuText .= "Press 1 for Sunday, 2 for Monday, 3 for Tuesday, "; $menuText .= "4 for Wednesday, 5 for Thursday, 6 for Friday, "; $menuText .= "7 for Saturday. Press 8 for the credits. "; $menuText .= "Press 9 to enter in a new zipcode. "; $menuText .= "Press 0 to hang up."; $gather->say($weather . $menuText); return $response; }
The getWeather method takes a zipcode with the day of the week and crafts the text of a weather forecast. First, it figures out the reference time for the day requested, and then looks up the weather forecast by doing a foreach over the array of forecast data. After that, it returns a Voice TwiML response. Below is a sample of what is returned:
<?xml version="1.0" encoding="UTF-8"?> <Response> <Gather numDigits="1" action="/voice/dayWeather"> <Say> This Afternoon the 31st: Sunny, with a high near 72. South southwest wind around 8 mph. Press 1 for Sunday, 2 for Monday, 3 for Tuesday, 4 for Wednesday, 5 for Thursday, 6 for Friday, 7 for Saturday. Press 8 for the credits. Press 9 to enter in a new zipcode. Press 0 to hang up. </Say> </Gather> </Response>
The <Gather> tag tells Twilio to expect input from the user's keypad. The numDigits attribute says how many digits to expect. The action attribute says what endpoint to contact next.
protected function retrieveNwsData($zip) { return Cache::remember('weather:' . $zip, 60, function () use ($zip) { $point = $this->getPoint($zip); $point = $point->lat . ',' . $point->lng; $url = 'http://ift.tt/2siEbBl' . $point . '/forecast'; $client = new \GuzzleHttp\Client(); $response = $client->request('GET', $url, [ 'headers' => [ 'Accept' => 'application/geo+json', ] ]); return json_decode((string)$response->getBody()); }); }
The retrieveNwsData method gets the weather forecast data. First, the method checks to see if a copy of the zipcode's weather forecast is in cache. If not, then the Guzzle HTTP client is used to make an HTTP GET request to the National Weather Service's (NWS) API endpoint http://ift.tt/2siJ4Kk. To get the geographic point of the zipcode, a call is made to the getPoint method before doing the request to the weather API. The response from the API endpoint is the weather forecast in GeoJSON format. The forecast is for every day and night for a week (with some exceptions we will discuss later); 14 entries in all. We cache the API response for an hour because making the request is slow, plus we do not want to hit the government servers too frequently and get banned.
protected function getPoint($zip) { return Cache::remember('latLng:' . $zip, 1440, function () use ($zip) { $client = new \GuzzleHttp\Client(); $url = 'http://ift.tt/1p5neFv'; $response = $client->request('GET', $url, [ 'query' => [ 'postalcode' => $zip, 'countryBias' => 'US', 'username' => env('GEONAMES_USERNAME') ] ]); $json = json_decode((string)$response->getBody()); return $json->postalCodes[0]; }); }
The getPoint method maps a zipcode to a geographic point. This is done by using the GeoNames API. The results are cached for a day because using the API is slow.
protected function getTimeZone($point) { $key = 'timezone:' . $point->lat . ',' . $point->lng; return Cache::remember($key, 1440, function () use ($point) { $client = new \GuzzleHttp\Client(); $url = 'http://ift.tt/1C9XM7m'; $response = $client->request('GET', $url, [ 'query' => [ 'lat' => $point->lat, 'lng' => $point->lng, 'username' => env('GEONAMES_USERNAME') ] ]); return json_decode((string) $response->getBody()); }); }
The getTimeZone method is used to get the timezone that a geographic point resides inside. The GeoNames API is also used and the results are cached for a day for the same reasons.
Continue reading %Hello, Laravel? Communicating with PHP through Phone Calls!%
by Christopher Thomas via SitePoint http://ift.tt/2rwsNPa
0 notes
bitfumes-blog · 8 years ago
Text
Laravel 5.3 Hindi Beginner Tutorials Part 7 - Resource Controller
Laravel 5.3 Hindi Beginner Tutorials Part 7 – Resource Controller
Laravel 5.3 Hindi Beg inner Tutorials Part 7 – Resource Controller 
A controller is a place where you can define all your logic. It can handle your requests and proccess it accordingly. Laravel resource routing assigns the typical “CRUD” routes to a controller with a single line of code
Here is a new series for Beginner on Laravel…
View On WordPress
0 notes