Posts

Showing posts with the label Freelance Developer

Laravel 5.5 save filename to database as *.tmp - development

Laravel 5.5 save filename to database as *.tmp I want to save my post with linked image/ My model: class Performer extends Model { protected $fillable = ['title','slug','logoimage','description','address','toplace','exp','workers','published','created_by','modified_by']; public function categories() { return $this->morphToMany('AppCategory', 'categoryable'); } public function SetSlugAttribute($value) { $this->attributes['slug'] = Str::slug(mb_substr($this->title, 0, 40) . "-". CarbonCarbon::now()->format('dmyHi'), '-'); } } My controller: public function store(Request $request) { // dd($request); $performer = Performer::create($request->all()); if ($request->input('categories')){ $performer->categories()->attach($request->input('categ...

Add more column in existing table but it doesn’t [duplicate] - development

Add more column in existing table but it doesn’t [duplicate] This question already has an answer here: Laravel migration add colum issue in existing database table 1 answer $ php artisan migrate In Connection.php line 647: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists (SQL: create table `users` (`id` int unsigned not null auto_incr ement primary key, `name` varchar(191) not null, `email` varchar(191) not n ull, `password` varchar(191) not null, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci) In Connection.php line 449: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists I am trying to add more column into users table but I can’t. In terminal I write command php artisan migrate but Base table or view already exists: 1050 Table ‘users’ already exists. What can I...

Laravel on Window 10 using Wamp gives and error - development

Laravel on Window 10 using Wamp gives and error I installed Laravel(5.6) on windows 10 with Wamp(3.1.) . When I run the index file in Public folder in laravel to check if it is correctly installed or not using browser url, I get the following error: Parse error: syntax error, unexpected ‘?’ in C:wamp64wwwlaravelvendorlaravelframeworksrcIlluminateFoundationhelpers.php on line 242. So how can I solve this? from Laravel Questions and Answers https://laravelquestions.com/php/laravel-on-window-10-using-wamp-gives-and-error/ via Lzo Media

Laravel Eloquent with() method works with ‘where’ but doesn’t work with ‘Model::find’ - development

Image
Laravel Eloquent with() method works with ‘where’ but doesn’t work with ‘Model::find’ I want to have relationship between 3 tables, using Laravel Eloquent with() method . this is my code ( relationships are set in models ): $request_form = RequestForm::find(7)->with(['RequestFormsCheck' => function ($q) { $q->orderBy("created_at", "DESC")->with('RequestFormsCheckOptions'); }])->get(); dd($request_form); but this code returns all request forms except returning only id = 7 this is output: Collection {#895 ▼ #items: array:4 [▼ 0 => RequestForm {#796 ▶} 1 => RequestForm {#797 ▶} 2 => RequestForm {#798 ▶} 3 => RequestForm {#799 ▶} ] } when I replace ->get() with ->first() it returns just request form , but its id is 1 but this code works great: $request_form = RequestForm::where('id', 7)->with(['RequestFormsCheck' => function ($q) { ...

Laravel- arranging records in ascending and descending order - development

Laravel- arranging records in ascending and descending order I have a create method in my controller public function create() { $image = PropertyUser::where('user_id', '=', Auth::user()->id)->get(); foreach($image as $property) { $id = $property->property_id; } $image_main = Image::where('property_id', $id)->get(); return view('settings.photos', ['image_array' => $image_main]); } This is my photos.blade file <form name="asc" action="" method="post" class="text-center"> @csrf <input type="submit" value="Ascending " class="settings-photos-header2 text-center"/> | </form><form name="dec" action="" method="post" class="text-center"> @csrf <input type="submit" value= " Descending" class="settings-photos-header2 text-center"/> </form>...

Using Intervention package to compress images. My images are not being compressed, still the same size - development

Using Intervention package to compress images. My images are not being compressed, still the same size I’m using this package http://image.intervention.io/getting_started/installation to compress my images that’s uploaded to my server. However the images are not being compressed. First I installed the Intervention package by putting this in my terminal: composer require intervention/image Then I added this at the top of my controller: use InterventionImageImageManagerStatic as Image; Then I added the encode to minify the image Image::make(request()->file(‘img’))->encode(‘jpg’, 1); It’s not minifying the image. It’s still the same size. <?php namespace AppHttpControllers; use InterventionImageImageManagerStatic as Image; use IlluminateSupportFacadesStorage; use IlluminateHttpRequest; class UploadsController extends Controller { public function store() { // Get image $img = request()->file('img'); // Mini...

URL generation removes port - development

URL generation removes port I was trying to send an email when I encountered this error. So what I did is I created an event and on it’s listeners I want to send an email that will validate it’s email address. Just to be sure that everything will be secure I tried using URL::signedRoute to create a URL wherein if the user would click on it, it will go to the address produced by URL::signedRoute. What I just notice is that on the url that it created, there was no port in it. Heres my mailable class <?php namespace AppMail; use AppUser; use IlluminateBusQueueable; use IlluminateMailMailable; use IlluminateQueueSerializesModels; use IlluminateContractsQueueShouldQueue; use IlluminateSupportFacadesURL; class AccountValidation extends Mailable { use Queueable, SerializesModels; public $user,$link; public function __construct(User $user) { $this->user = $user; $this->link = URL::temporarySignedRoute( 'activateaccount', now...

count in laravel 5.3 - development

count in laravel 5.3 I want to count table users row in laravel 5.3. Here is my code Controller: public function admin(){ $jumlah['data'] = DB::table('users')->get(); return view('admin',$jumlah); } In view, I call this count with : Then I run and I get the message: Undefined variable: jumlah (View: C:xampphtdocsBiroUmumresourcesviewsdashboardadmin.blade.php) from Laravel Questions and Answers https://laravelquestions.com/php/count-in-laravel-5-3/ via Lzo Media

Get many to many from polymorphic table ID - development

Get many to many from polymorphic table ID Using Laravel 5.1, how can I get Dialogs from a M:M relationship with a Polymorphic table. When I load tasks , it loads the appropriate npc . This relationship between tasks and npcs is a Polymorphic relation. So I created another M:M table, dialog_npcseventsmorphable , that links the dialog_id to the npcs_events_morphable_id on npcs_events_morphable table, but it is not loading the dialogs . $task = Task::findOrFail(1); npcs_events_morphable: id | npc_id | morphable_id | morphable_type | created_at | updated_at | published_at ----+--------+--------------+----------------+---------------------+---------------------+--------------------- 1 | 1 | 1 | AppTask | 2018-05-20 04:45:24 | 2018-05-20 04:45:24 | 2018-05-20 04:45:24 2 | 2 | 1 | AppActivity | 2018-05-20 04:45:24 | 2018-05-20 04:45:24 | 2018-05-20 04:45:24 3 | 3 | 1 | AppBattle | 2018...

Convert row data into column data using Laravel - development

Convert row data into column data using Laravel Hello I am facing a problem. I am trying at my best to solve this but can not. I am trying to do this I have three table which is illustrated below image. I want to Output like last table in the given image And this is my laravel code—————— $academic_year=$request->academic_year; $class=$request->class_name; $medium=$request->medium; $section=$request->section_name; $exam_name=$request->exam_name; $subject_list=DB::table('tbl_subject') ->where('class_name', 'LIKE', "%$class%") ->get(); $student_all_subject_mark_search_result=DB::table('tbl_student_subject_mark') ->join('tbl_student_admission', 'tbl_student_subject_mark.student_registration_id', '=', 'tbl_student_admission.stude...

Why Design layout does not work in laravel in auth:make command - development

Image
Why Design layout does not work in laravel in auth:make command I’m new to laravel and I’m using laravel 5.6 but the problem is when I run auth:make command it execute and display some login field and register field. My question is why design layout is not working after running auth:make command in laravel. I have uploaded image it shows only html content but design layout is not showing. from Laravel Questions and Answers https://laravelquestions.com/php/why-design-layout-does-not-work-in-laravel-in-authmake-command/ via Lzo Media

how to change tymon jwt authentication to use member model instead of user model in laravel 5.6? - development

how to change tymon jwt authentication to use member model instead of user model in laravel 5.6? In my project I have users and members tables and eloquent models. I’m going to use jwt authentication in members table and I changed corresponding config files, but still it goes to User model. Here is config/auth.php : return [ /* |-------------------------------------------------------------------------- | Authentication Defaults |-------------------------------------------------------------------------- | | This option controls the default authentication "guard" and password | reset options for your application. You may change these defaults | as required, but they're a perfect start for most applications. | */ 'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ], /* |-------------------------------------------------------------------------- | Authentication Guards |-----------------------------------...

set laravel mail setting to log file - development

set laravel mail setting to log file I just start to learning laravel and now I have a problem with mail settings. I want to send reset password email to the log file of the project and for this I change the .env file settings from MAIL_DRIVER = smtp to MAIL_DRIVER = log I also change the mail.php settings and reset my server because I use (php artisan serve) command. still i receive following error SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘mytodo.password_resets’ doesn’t exist (SQL: delete from password_resets where email = Ali@gmail.com I don’t know why it is search for table. I also see the following question it has same problem but my problem doesn’t solve by their instruction. Laravel Mail to Log please help me is there anything else i should try. from Laravel Questions and Answers https://laravelquestions.com/laravel/set-laravel-mail-setting-to-log-file/ via Lzo Media

How to use Laravel’s 5.6 native Auth functionality with MongoDB - development

How to use Laravel’s 5.6 native Auth functionality with MongoDB I am using the first-time laravel, and want to use the laravel Auth for login and registration, MongoDB as backend. Using this command enables the laravel Auth php artisan make:auth will it work ? can anyone help me, how to do it.. from Laravel Questions and Answers https://laravelquestions.com/laravel/how-to-use-laravels-5-6-native-auth-functionality-with-mongodb/ via Lzo Media

Link to a specific part of a page - development

Link to a specific part of a page I have a div that has lots of posts which is created dynamically from the database. The div has input for comment facility as well. I have no problems in posting the comments and I do it using a POST method. Then I redirect to the page using return redirect('/'); method. But it links to the beginning to the page which doesn’t create a good impression on the user. The user might be in the middle of the page and when he/she comments he will go to the beginning of the page and will have to scroll down again. Luckily, I have the divs with class equal to the post_id. So, isn’t there any method to go to the post in which the user posted using that class? from Laravel Questions and Answers https://laravelquestions.com/php/link-to-a-specific-part-of-a-page/ via Lzo Media

View not loading when called from a Controller in Laravel - development

View not loading when called from a Controller in Laravel I created a controller using artisan in my Laravel application, here’s the code: <?php namespace AppHttpControllers; use IlluminateHttpRequest; class NavigationController extends Controller { public function welcome() { return view("welcome"); } } When I use a Closure or load the view directly, everything works fine. But, when I load view from inside a controller, it couldn’t find it. Here’s my web.php file’s code: Route::get('/', function () { return view('NavigationController@welcome'); }); The error it shows: InvalidArgumentException View [NavigationController@welcome] not found. from Laravel Questions and Answers https://laravelquestions.com/php/view-not-loading-when-called-from-a-controller-in-laravel/ via Lzo Media

Laravel get input data from POST request in a rest api - development

Image
Laravel get input data from POST request in a rest api i’m trying to get input data which i post them from rest api as an json format, but in laravel i can’t get them on controller and that return empty array of request my api route: Route::group(['prefix' => 'v1', 'namespace' => 'Apiv1'], function () { $this->post('login', 'ApiController@login'); }); and ApiController : <?php namespace AppHttpControllersApiv1; use AppHttpControllersController; use IlluminateHttpRequest; use IlluminateSupportFacadesValidator; class ApiController extends Controller { public function login(Request $request) { dd($request->all()); } } output: [] ScreenShot from Laravel Questions and Answers https://laravelquestions.com/laravel/laravel-get-input-data-from-post-request-in-a-rest-api/ via Lzo Media

How to get the time at which the current user logged in in Laravel? - development

How to get the time at which the current user logged in in Laravel? I’m using Laravel Authentication . How can I get the time at which the current user logged in? I want to calculate the number of seconds that have passed since the current user logged in. If there is a way to achieve it without using Events , it would be great. from Laravel Questions and Answers https://laravelquestions.com/php/how-to-get-the-time-at-which-the-current-user-logged-in-in-laravel/ via Lzo Media

Project Specific PHP Error Log in Laravel Valet - development

Project Specific PHP Error Log in Laravel Valet I just wanted to log PHP errors inside laravel project folder using Valet. For Example – in Apache2 we can add php error log path (in my case my project folder) in virtual host and every time we add error_log($var); that will log errors inside project folder. is it possible to create PHP Error log in Valet like so ? from Laravel Questions and Answers https://laravelquestions.com/php/project-specific-php-error-log-in-laravel-valet/ via Lzo Media

Calculate average from array with fmod() - development

Calculate average from array with fmod() I have a ratings array in which there are list of ratings of particular product from where i want the result to be average rating. What i want to achieve is if average rating is 4.2 or 4.3 or something in between 4 to 4.5 it should result as 4.5 and if average rating is like 4.6 or 4.7 or something it should result as 5 rating. I have done below stuff which is resulting 4.5 still if average rating os 4.2 or 4.6. $product_ratings = Array ( [0] => stdClass Object ( [id] => 93 [product_id] => 5 [rating] => 5 [user_id] => 154 ) [1] => stdClass Object ( [id] => 93 [product_id] => 5 [rating] => 5 [user_id] =...