Posts

Showing posts with the label Laravel

Apache Virtual Host Always Redirecting To /dashboard

Answer : Put this as the first line in C:\...\httpd-vhosts.conf (and restart the web server): NameVirtualHost *:80 So, it should look like this: NameVirtualHost *:80 <VirtualHost *:80> ServerName localhost DocumentRoot "C:/xampp/htdocs" </VirtualHost> <VirtualHost *:80> ServerName walkpeakdistrict.local DocumentRoot "C:/xampp/htdocs/walkpeakdistrict_uk/public" </VirtualHost> I would place all my projects somewhere outside of C:/xampp/htdocs and C:/xampp . Let C:/xampp/htdocs be the standard localhost location, with just two files inside (simple index.php and index.html ), but use another one for the projects. Even better, use another partition, not the system partition C: . Like D:/projects , or so. So, you would have D:/projects/walkpeakdistrict_uk . Good luck. Ok, I'm not sure why this was an issue but it seems to work when I change the virtual host's server name to anything other than ".loca...

Base Table Or View Not Found: 1146 Table Laravel 5

Answer : I'm guessing Laravel can't determine the plural form of the word you used for your table name. Just specify your table in the model as such: class Cotizacion extends Model{ public $table = "cotizacion"; Check your migration file, maybe you are using Schema::table, like this: Schema::table('table_name', function ($table) { // ... }); If you want to create a new table you must use Schema::create: Schema::create('table_name', function ($table) { // ... }); I faced this problem too in laravel 5.2 and if declaring the table name doesn't work,it is probably because you have some wrong declaration or mistake in validation code in Request (If you are using one)

BrowserSync Cannot GET /

Answer : Using BrowserSync as a server only works if you're running a static site, so PHP won't work here. Looks like you're using XAMPP to serve your site, you can use BrowserSync to proxy your localhost. Example: browser-sync start --proxy localhost/yoursite References: http://www.browsersync.io/docs/command-line/#proxy-example https://github.com/BrowserSync/browser-sync/issues/5 Because it works only with index.html by default, for example: linux@linux-desktop:~/Templates/browsersync-project$ ls brow.html css linux@linux-desktop:~/Templates/browsersync-project$ browser-sync start --server --files '.' Expected result: Cannot GET/ In order to see your static web-page in the web-browser instead of that annoying message you have to rename a file brow.html to index.html . This will solve Cannot GET/ problem. P.S. Where you are installing a browser-sync doesn’t matter. Just type npm install -g browser-sync whatever directory you are in...

Ajax File Upload With Form Data Laravel 5.3

Answer : Try using the FormData in ajax while you upload a file. Just try this $('form').submit(function(event) { event.preventDefault(); var formData = new FormData($(this)[0]); $.ajax({ url: '{{ url('/agents') }}', type: 'POST', data: formData, success: function(result) { location.reload(); }, error: function(data) { console.log(data); } }); }); OR You can try with this jQuery library https://github.com/malsup/form EDIT public function store(Request $request) { if (User::where('phone_number', '=', Input::get('phone_number'))->exists()) { return $this->respondBadRequest('Phone Number Exists'); } else { $user=User::create($request->all()); if($request->hasFile('image')) { $file = $request->file('i...

403 Forbidden On Nginx/1.4.6 (Ubuntu) - Laravel

Answer : You need to specify an absolute path for your root directive. Nginx uses the directory set at compile time using the --prefix switch. By default this is /usr/local/nginx . What this means is that your root, which is currently set to root home/laravel-app/ causes nginx to look for files at /usr/local/nginx/home/laravel-app/ which presumably isn't where your files are. If you set your root directive to an absolute path such as /var/www/laravel-app/public/ nginx will find the files. Similarly you'll note that I added /public/ to the path above. This is because Laravel stores it's index.php file there. If you were to just point at /laravel-app/ there's no index file and it'd give you a 403.

413 Request Entity Too Large

Answer : Add ‘client_max_body_size xxM’ inside the http section in /etc/nginx/nginx.conf, where xx is the size (in megabytes) that you want to allow. http { client_max_body_size 20M; } I had the same issue but in docker. when I faced this issue, added client_max_body_size 120M; to my Nginx server configuration, nginx default configuration file path is /etc/nginx/conf.d/default.conf server { client_max_body_size 120M; ... it resizes max body size to 120 megabytes. pay attention to where you put client_max_body_size , because it effects on its scope. for example if you put client_max_body_size in a location scope, only the location scope will be effected with. after that, I did add these three lines to my PHP docker file RUN echo "max_file_uploads=100" >> /usr/local/etc/php/conf.d/docker-php-ext-max_file_uploads.ini RUN echo "post_max_size=120M" >> /usr/local/etc/php/conf.d/docker-php-ext-post_max_size.ini RUN echo ...

Bulk Insertion In Laravel Using Eloquent ORM

Answer : You can just use Eloquent::insert() . For example: $data = array( array('name'=>'Coder 1', 'rep'=>'4096'), array('name'=>'Coder 2', 'rep'=>'2048'), //... ); Coder::insert($data); We can update GTF answer to update timestamps easily $data = array( array( 'name'=>'Coder 1', 'rep'=>'4096', 'created_at'=>date('Y-m-d H:i:s'), 'modified_at'=> date('Y-m-d H:i:s') ), array( 'name'=>'Coder 2', 'rep'=>'2048', 'created_at'=>date('Y-m-d H:i:s'), 'modified_at'=> date('Y-m-d H:i:s') ), //... ); Coder::insert($data); Update: to simplify the date we can use carbon as @Pedro Moreira suggested $now = Carbon::now('utc')->toDateTimeString(); $data = array( ...

Add "ON DELETE CASCADE" To Existing Column In Laravel

Answer : Drop foreign key first. Thanks to Razor for this tip $table->dropForeign('answers_user_id_foreign'); $table->foreign('user_id') ->references('id')->on('users') ->onDelete('cascade'); $table->foreign('user_id') ->references('id')->on('users') ->onDelete('cascade'); In my case, i'll need to put the col name in an array else that will be an error. Schema::table('transactions', function (Blueprint $table) { $table->dropForeign(['transactions_order_id_foreign']); $table->foreign('order_id') ->references('id')->on('orders') ->onDelete('cascade') ->change(); }); mysql 5.7 ver

Change The Database Connection Dynamically In Laravel

Answer : This way you can set new parameter when it comes to database: \Config::set('database.connections.mysql.database', $schemaName); Remember about PURGE to persist this settings DB::purge('mysql'); Cheers! Well you can use the default database for user login and have a new field for the database name. Then whenever you need to query a different database, you can just change your db connection. Something like this $someModel = new SomeModel; $databaseName = "mysql2"; // Dynamically get this value from db $someModel->setConnection($databaseName); $something = $someModel->find(1); You can read more about it here. http://fideloper.com/laravel-multiple-database-connections you need to get the config first.. then alter the specific field then set it back.. $config = Config::get('database.connections.company'); $config['database'] = "company_tenant_$id"; $config['password'] = "test2123";...

A __construct On An Eloquent Laravel Model

Answer : You need to change your constructor to: public function __construct(array $attributes = array()) { parent::__construct($attributes); $this->directory = $this->setDirectory(); } The first line ( parent::__construct() ) will run the Eloquent Model 's own construct method before your code runs, which will set up all the attributes for you. Also the change to the constructor's method signature is to continue supporting the usage that Laravel expects: $model = new Post(['id' => 5, 'title' => 'My Post']); The rule of thumb really is to always remember, when extending a class, to check that you're not overriding an existing method so that it no longer runs (this is especially important with the magic __construct , __get , etc. methods). You can check the source of the original file to see if it includes the method you're defining.

Can Anyone Explain Laravel 5.2 Multi Auth With Example

Answer : After lots of digging and lots of questions & answers I have finally managed to work Laravel 5.2 Multi Auth with two table, So I'm writing Answer of my own Question. How to implement Multi Auth in Larvel 5.2 As Mentioned above. Two table admin and users Laravel 5.2 has a new artisan command. php artisan make:auth it will generate basic login/register route , view and controller for user table. Make a admin table as users table for simplicity. Controller For Admin app/Http/Controllers/AdminAuth/AuthController app/Http/Controllers/AdminAuth/PasswordController (note: I just copied these files from app/Http/Controllers/Auth/AuthController here) config/auth.php //Authenticating guards 'guards' => [ 'user' =>[ 'driver' => 'session', 'provider' => 'user', ], 'admin' => [ 'driver' => 'session', 'pro...

Change Timezone In Laravel

Answer : go to the file config/app.php and look for this entry: /* |-------------------------------------------------------------------------- | Application Timezone |-------------------------------------------------------------------------- | | Here you may specify the default timezone for your application, which | will be used by the PHP date and date-time functions. We have gone | ahead and set this to a sensible default for you out of the box. | */ 'timezone' => 'Asia/Tehran', //There will be default 'UTC' here As you can see, UTC is a default value for Laravel. So you can easily change it here to, like: 'timezone' => 'Asia/Tehran', - See full list PHP Supported Timezones After changes app.php you should run this command php artisan config:cache After update app.php run below command and check php artisan config:cache php artisan cache:clear You can create below type of route for clear cache in laravel Route::get(...

Available Actions For OnUpdate / OnDelete In Laravel 5.x

Answer : You can do all the options mentioned in phpmyadmin this way: $table->...->onDelete('CASCADE'); $table->...->onDelete('SET NULL'); $table->...->onDelete('RESTRICT'); // do not call the onDelete() method if you want the RESTRICT option. You have to make sure you set the foreign key field as nullable: $table->...->unsigned()->nullable(); Referring to the source code: `vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/Grammar.php` in the function compileForeign() It just appends whatever you pass in to the table query. if (! is_null($command->onDelete)) { $sql .= " on delete {$command->onDelete}"; } if (! is_null($command->onUpdate)) { $sql .= " on update {$command->onUpdate}"; } So, make sure you pass one of the following: "cascade", "no action", "restrict", or "set null" NOTE: Do NOT use...