Posts

Github Account Deleter

I've made a simple presentation on how to create a simple python script to delete the repos that you dont need anymore https://colab.research.google.com/drive/13BBnj7JBTOwrIOWRrrS9xuDoRWZC04ja

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] =...

Laravel 5.6 and reflection not finding class - development

Laravel 5.6 and reflection not finding class I’m building a package in Laravel 5.6, im very new to building packages so im cutting and copying and learning as I go. so far so good, except i have run into a little issue. My main package class is in packages/vendor/packagename/src/packagename.php In that file, it is using a foreach loop to loop over the classes which i have inserted into the config file, so for example, i have a controller in app/Http/Controllers/TestController // $class in this case equals TestController foreach ( $allclasses as $class ) { $classMethods = []; $reflection = new ReflectionClass( $class ); } When I run the code, i keep getting the following error; Class TestController does not exist The original code that i am copying this part from is found here https://github.com/Bulforce/laravel-ext-direct/blob/master/src/Bulforce/ExtDirect/ExtDirect.php at line 133. I am taking the above code and building it for Laravel 5.6. My TestController doe...

Laravel Creating relationship while updating - development

Laravel Creating relationship while updating I have a library management system with Student and Book model. The structure of the tables are Students Table id | roll_no | name | created_at | updated_at Books Table book_id | name | author | publication | student_id | created_at | updated_at Here, boook_id is the primary key The relation is as follows In Book Model public function student() { return $this->belongsTo('AppStudent'); } In Student Model public function books() { return $this->hasMany('AppBook'); } Initially the student_id in books table is null . Whenever a book is to be issued, book number and student roll number is supplied and the student_id field in books table is updated with the id of the student to whom it is being issued. In the controller, I have the following code public function postIssue(Request $request) { $this->validate($request, [ 'rollno' => 'required|min:7', ...

unable to find index for $geoNear query while using Laravel and MongoDB using Moloquent - development

unable to find index for $geoNear query while using Laravel and MongoDB using Moloquent I am using the Moloquent model with Laravel 5.6. here is my collection record given below:- { "_id" : ObjectId("5afe619dbe0b8d0e5876b16b"), "name" : "Central Park", "categories" : [ "4d4b7105d754a06376d81259", "4bf58dd8d48988d116941735", "4bf58dd8d48988d119941735", "4d4b7105d754a06376d81259", "4bf58dd8d48988d116941735", "4bf58dd8d48988d119941735", "4d4b7105d754a06374d81259", "4bf58dd8d48988d16d941735" ], "loc" : { "type" : "Point", "coordinates" : [ 88.4166612820784, 22.5835157504658 ] } } I am running this query from the Laravel controller. $users = MongoTest::where('loc',...

after filtering a plucked laravel collection, the indexed array change to Associative array - development

after filtering a plucked laravel collection, the indexed array change to Associative array I have a collection of model eloquent such as user model, i use the pluck method to get the only post_id from this collection, this method give me the indexed array of post_id , but when i use filter or unique method for this indexed array the result change to Associative array . i don’t want a assoc array in result. I want just the unique of post_id’s in the indexed array . laravel auto changing my result. $this->posts->pluck('post_id')->unique('post_id') result is : { "1": 1 , "2": 2 } . Is this can a bug or I have a mistake in fetching data by methods? from Laravel Questions and Answers https://laravelquestions.com/laravel/after-filtering-a-plucked-laravel-collection-the-indexed-array-change-to-associative-array/ via Lzo Media

How to implement OCR in website using Laravel - development

How to implement OCR in website using Laravel I need to implement OCR searching on my website using Laravel. How can I implement this in Laravel? Is this can be done only by open source OCR? Any suggestion is appreciable. Thanks from Laravel Questions and Answers https://laravelquestions.com/php/how-to-implement-ocr-in-website-using-laravel/ via Lzo Media

Check duplication while uploading to database - development

Check duplication while uploading to database I need to find duplicated details in the existing table while uploading a Excel file that contains some details,i need to find that by phone number and customer name. I am using mattexcel to upload the data into database. I don’t want to insert that details if it is in there but other details must insert into that table Controller public function importExcel(Request $request) { if ($request->hasFile('import_file')) { Excel::load($request->file('import_file')->getRealPath(), function ($reader) { foreach ($reader->toArray() as $key => $row) { $data['customername'] = $row['customername']; $data['chassis'] = $row['chassis']; $data['model'] = $row['model']; $data['branchcode'] = $row['branchcode']; $data['...

Composer update is slow - development

Image
Composer update is slow Whenever I use composer update, some packages are installing they will be installed, but it’s slow. I and when it comes to this package, it just wont download, when I check my resources monitor, vagrant download speed is only 8 to 10kbps. I have tried disabling xdebug by going to /etc/php/7.2/ . I have tried adding –prefer-dist still same problem. What would be the solution for this? Thank you! from Laravel Questions and Answers https://laravelquestions.com/laravel/composer-update-is-slow/ via Lzo Media

Laravel Image ( Working on store image ) - development

Laravel Image ( Working on store image ) I am working on a laravel store image function. Fortunately it is working. But my problem is when I’m trying to upload atleast 20+ images. It only stores the first 20 images. My question is, is there any settings that restricts my code to upload 20+ more files ? Here is my code public function storeImages($keycode, $projectsID){ if(!empty($_FILES[$keycode]['name']) && isset($_FILES[$keycode]) && is_array($_FILES[$keycode]['name'])): for($i = 0; $i < count($_FILES[$keycode]['name']); $i++): $filename = preg_replace("/[^a-z0-9A-Z.]/","_",$_FILES[$keycode]['name'][$i]); move_uploaded_file($_FILES[$keycode]['tmp_name'][$i],"uploads/projects/".$filename); //stores original size try{ if(trim($filename) != ""){ $img = Image::make("uploads/projects/".$filenam...

Slack notification for Laravel as it should be. Easy, fast, simple and highly testable. - development

Image
Slack notification for Laravel as it should be. Easy, fast, simple and highly testable. submitted by /u/Salamandra5 [link] [comments] from Laravel Questions and Answers https://laravelquestions.com/rlaravel/slack-notification-for-laravel-as-it-should-be-easy-fast-simple-and-highly-testable/ via Lzo Media

Loop image in controller - development

Loop image in controller MY CODE IN CONTROLLER : public function image_item_name($inc) { if(isset($_POST['inc'])) { $inc = $_POST['inc']; $i = DB::select("SELECT file_name FROM tbl_image_item_name WHERE inc = '$inc';"); foreach ($i as $a){ echo '<img src="../../">'; } }else { echo "Access Denied"; } The Problem : I cannot to loop the image from database, please help me. from Laravel Questions and Answers https://laravelquestions.com/laravel/loop-image-in-controller/ via Lzo Media

Video not working validation Laravel - development

Video not working validation Laravel This is my code for the image the validation works but for audio and video does not work.. private function getFileRules(){ return array('question_image' => 'mimes:jpeg,jpg,png|max:10000', 'question_audio' => 'max:30000', 'question_video' => 'present|file|mimetypes:video/mp4,video/ogg|max:10000'); } private function isFileValid($request){ $rules = self::getFileRules(); $validator = Validator::make($request->all(), $rules); if($validator->fails()){ return false; }else{ return true; } } Why it does not work since it is the same code.?! from Laravel Questions and Answers https://laravelquestions.com/laravel/video-not-working-validation-laravel/ via Lzo Media

Convert SQL Inner Join Custom to Eloquent Laravel - development

Convert SQL Inner Join Custom to Eloquent Laravel Can I convert my custom SQL syntax into Eloquent Laravel, this is my SQL syntax: SELECT a.* FROM krs a INNER JOIN ( SELECT kode_matakuliah, MAX(bobot) as bobot_max FROM krs WHERE nim = 133341043 GROUP BY kode_matakuliah ) b ON a.bobot = b.bobot_max AND a.kode_matakuliah = b.kode_matakuliah WHERE nim = 133341043 from Laravel Questions and Answers https://laravelquestions.com/laravel/convert-sql-inner-join-custom-to-eloquent-laravel/ via Lzo Media

Laravel serve – can’t post - development

Laravel serve – can’t post I’m trying to build an API and wamp is having issues with the OAuth so I am using Laravel Serve. I am using Laravel 5.3 Passport, each time I POST , the response is blank and doesn’t respond the correct headers (Access-Control-Allow-Origin) . It’s also only taking 9MS to get the response (which should be much longer, close to 600MS with PUT ). However, if I use PUT , it works correctly. VUE: Vue.http.headers.common['Accept'] = 'application/json'; Vue.http.headers.common['Authorization'] = 'Bearer ' + token; this.$http.post('http://127.0.0.1:8000/api/post/' + this.post.id + '/comment', formData) .then(response => { console.log(response); }, response => { // error }); Middleware: protected $middleware = [ BarryvdhCorsHandleCors::class, ]; protected $middlewareGroups = [ 'api' => [ 'throttle:60,1',...

Creating a test for password reset email – getting error (mailable not queued) when running test - development

Creating a test for password reset email – getting error (mailable not queued) when running test I am using the auth that came with Laravel. I am testing the page where you put in your email and when you hit the submit button a password reset email will be sent to your email. The password reset email is sent when I do it manually. But I created this test to make sure the password reset email is sent but it's not working. I am getting this error: There was 1 failure: 1) The expected [IlluminateFoundationAuthResetPassword] mailable was not queued. Failed asserting that false is true. I am using this code as a guide: https://github.com/JeffreyWay/council/blob/master/tests/Feature/Auth/RegisterUserTest.php <?php namespace TestsControllersUnit; use TestsTestCase; use IlluminateSupportFacadesMail; use IlluminateAuthNotificationsResetPassword; use IlluminateFoundationTestingRefreshDatabase; class ResetPasswordEmailTest extends TestCase { use RefreshDatabase; public function ...

(1/1) FatalErrorException Call to a member function hasPermissionTo() on null in ClearanceMiddleware.php line 17 - development

(1/1) FatalErrorException Call to a member function hasPermissionTo() on null in ClearanceMiddleware.php line 17 https://scotch.io/tutorials/user-authorization-in-laravel-54-with-spatie-laravel-permission . I have followed the above link for my reference to set roles and permissions to users. I am getting the error. (1/1) FatalErrorException Call to a member function hasPermissionTo() on null in ClearanceMiddleware.php line 17 My db tables are This is my db table Cleareance middleware code is: namespace AppHttpMiddleware; use Closure; use IlluminateSupportFacadesAuth; class ClearanceMiddleware { /** * Handle an incoming request. * * @param IlluminateHttpRequest $request * @param Closure $next * @return mixed */ public function handle($request, Closure $next) { if (Auth::user()->hasPermissionTo(‘Administer roles & permissions’)) //If user has this //permission { return $next($request); } if ($request->is('posts/create'))//If user is creat...

Ajax page load with get parameter in Laravel 5.6 - development

Image
Ajax page load with get parameter in Laravel 5.6 I am new laravel learner. I started a small project for my personal website. I am facing a problem. First i am giving my source code Route: Route::get('/p/{id}','mainController@portfolio'); Controller method: public function portfolio($id) { $project = PortItems::where('id',$id)->first(); return view('kafi.p',['project' => $project]); } Link to Ajax File: @foreach($projects as $project) <figure class="item" data-groups='["all"]'> <a class="ajax-page-load" href=""> <img src="" alt=""> <div> <h5 class="name"></h5> <small></small> <i class="pe-7s-icon pe-7s-display2">...

RelationNotFoundException Call to undefined relationship [userStories] on model [AppUser] - development

Image
RelationNotFoundException Call to undefined relationship [userStories] on model [AppUser] I have created a relationship between User model and StoryModel . But it give me the Error Call to undefined relationship [userStories] on model [AppUser]. May by i am missing something. Following is my code which i am using Error: User.php <?php namespace App; use IlluminateNotificationsNotifiable; use IlluminateFoundationAuthUser as Authenticatable; use AppNotification; use AppCheckIn; use AppTravel; use CarbonCarbon; use AppNewInterest; use AppUserStory; class User extends Authenticatable { use Notifiable; protected $table = "users"; protected $primaryKey = 'id'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'firstname','lastname', 'user_id','email', ]; /** * The attributes that should be hidden for arrays. * * @var...

How to call different methods of other classes to make a sheet and then merge sheet return from these methods to a excel file in Laravel? - development

How to call different methods of other classes to make a sheet and then merge sheet return from these methods to a excel file in Laravel? I am using maatwebsite/Laravel-Excel to make excel sheet. What I need is I want to make 5 sheets in a single file I am able to make when using a common function to generate all sheets. But I want to make a sheet from the different function of some different class and then return this sheet to the calling function where we can merge different sheets to a single file. The scenario is that: 1. We have a function where we will make a single file with 5 sheets. Excel::create($fileName, function ($excel) use ($productArray){ //some code $excel->sheet($sheet_name, function ($sheet) use ($productArray){ if($sheet_name=='test'){ $x = new abcController; $y = $x->exportComment();//it should return a sheet so that it can be merged } }); }); For first sheet we call a method like $x = new ...

Retrieve files from Vue in Laravel - development

Retrieve files from Vue in Laravel I uploaded files from my frontend using Vue to Laravel backend. Uploaded using this snippet below: addPost() { axios.post('api/submitPropertyPhoto?token=' + this.token, this.postFormData) .then(r => { console.log(r) }) .catch(e => { console.log(e) } }, uploadFieldChange(e) { for(let key in e.target.files) { this.postFormData.append('images[]', e.target.files[key]) } } When I want to request the file using normal Laravel request file helper method it returns nothing but when I use dd($request->files) it returns the details below. FileBag {#68 #parameters: array:1 [ "images" => array:1 [ 0 => array:1 [ "name" => UploadedFile {#45 -test: false -originalName: "error.JPG" -mimeType: "image/jpeg" -size: 21806 -error: 0 path: "C:xampptmp" filename: "php639F.tmp" basename: "php639F.tmp...

Laravel 5 download excel file (maatwebsite/excel) under storage/export through AJAX - development

Laravel 5 download excel file (maatwebsite/excel) under storage/export through AJAX I want to download an excel file which stored into storage/export/ path. I used Maatwebsite excel provider for this in laravel 5.5. My controller code is written below: ob_end_clean(); ob_start(); Excel::create($excelName, function($excel) use($adminUserDataExcelSelected) { $excel->sheet('Sheet 1', function($sheet) use($adminUserDataExcelSelected) { $sheet->fromArray($adminUserDataExcelSelected); }); })->store('xlsx'); ob_flush(); return response()->json(['path' => $path]); My AJAX code is following; $.ajax({ url: "/administrator/adminUser/exportselected/1/", type:'POST', data: {_token:_token, selected:selected, selectedField:selectedField}, success: function(data) { alert(data.path); if($.isEmptyObject(data.error)){ }else{} } }); When I alert/ console.log the data.path, I received the below : /var/www/html/stmd_OLD/storage/export/Admi...

Structure for Products table to store products details from various fields - development

Structure for Products table to store products details from various fields I’m building an application which requires supporting various categories of fields of products (as in products in Fashion, Electronics, Automobile, Grocery etc.), so obviously, for products in every field (& even for their sub-categories), product properties would vary from category to category. Example: Products in Fashion field, are like Jeans, Shirts, etc. which have properties like size, color, type, material-type, etc. , whereas Products in Electronics , can be like Mobile phones, Laptops, etc. which can have product properties like, processor, memory, storage, size, color, etc. My Question is in regarding, how do I store such information in most generalized & efficient way possible? What I’ve thought of a solution: I’ve thought of creating three tables for maintaining this information. products table: This table will contain all products & their categories in nested set form such...

Variable in all controller and view fullcalendar laravel 5.6 - development

Image
Variable in all controller and view fullcalendar laravel 5.6 I use fullcalendar in my web site in laravel 5.6 and it working but when i change view i have this problem : Undefined variable: calendar_details In my view layout.app i have this : {!! $calendar_details->script() !!} Can i define this var in all controller and view to avoid all problem ? This is my EventsController.php namespace AppHttpControllers; use IlluminateHttpRequest; use IlluminateSupportFacadesRedirect; use AppHttpControllersController; use Auth; use Validator; use AppEvents; use Calendar; class EventsController extends Controller { public function index(){ $events = Events::get(); $event_list = []; foreach ($events as $key => $event){ $event_list[] = Calendar::event( $event->event_name, true, new DateTime($event->start_date), new DateTime($event->end_date) ); } ...

Laravel foreach ajax get HTTP 500 - development

Laravel foreach ajax get HTTP 500 This is my ajax $('#absensi').on('show.bs.modal', function (event) { var button = $(event.relatedTarget); var data_kelas = button.data('pkelas'); var id = button.data('pid'); var modal = $(this); //console.log(id); document.getElementById("vkelas").innerHTML = data_kelas; $.ajax({ type : 'get', url : '', data : {'id': id}, success:function(data){ console.log(data); //check $('#siswa').html(data); } }); }); This is My Controller $output=""; $admin = Auth::user()->sekolah_id; $murids= Student::where('sekolah_id', $admin) ->where('ruang_id', $request->id) ->get(); if ($murids) { $i=1; foreach ($murids as $murid) { $stu .= '<tr><td>'.$i++.'</td> ...

Laravel relationship across multiple tables fails - development

Laravel relationship across multiple tables fails I have the following tabels table check id name ... table setting type id name level //references id on table check tabel settings type, //references type on table setting type name value So basically i would like to return all checks with settings So i have in my models 1.Check model // references table check public function settingsval(){ return $this->hasMany('AppAppSettingTypes','name','name.setting'); } On my AppSettingTypes // references table setting type public function settings(){ return $this->hasMany('AppAppSetting','id','type'); } SO on my controller am simply doing CheckModel::with('settingsval') But everytime the settings array is empty even though there is data What could be wrong? from Laravel Questions and Answers https://laravelquestions.com/php/laravel-relationship-across-multiple-tables-fails/ ...

How to do auth without database in Laravel 5.6 - development

How to do auth without database in Laravel 5.6 I have to make default login in Laravel with: php artisan make:auth and I want to add 1 more authentication with API. In this auth API I don’t need database for login. Is there any solution for this case? I want to make custom provider and guard it but I am stuck at AlumniAuthProvider.php on AppAuth : <?php namespace AppAuth; use IlluminateContractsAuthUser as UserContract; use IlluminateContractsAuthAuthenticatable; use IlluminateContractsAuthUserProvider; use AppAuthUser; class AlumniAuthProvider implements UserProvider { public function alumni() { } public function retrieveById($identifier) { } public function retrieveByToken($identifier, $token) { } public function updateRememberToken(Authenticatable $user, $token) { } public function retrieveByCredentials(array $credentials) { } public function validateCredentials(Authenticatable $user, array...

How to insert AM and PM in Mysql Database ? Thanks in advance - development

How to insert AM and PM in Mysql Database ? Thanks in advance Thank You all for your precious time, I have seen lot of solution in internet for this problem, But cant get the apt solution for me This is my value, I am going to insert in my DB [phoneinterview] => 2018-05-16 10:28 PM In My databse I have field like this phoneinterview timestamp But Its Inserting Like this -> 2018-05-16 10:28:00 Actually I want to insert like this -> 2018-05-16 10:28 PM from Laravel Questions and Answers https://laravelquestions.com/php/how-to-insert-am-and-pm-in-mysql-database-thanks-in-advance/ via Lzo Media

Ignore unique validation while update data - development

Ignore unique validation while update data In my products table product_name is unique so while updating the data if i don’t update the product name it can’t let me update my product information and showing product name has already been taken My question is how to ignore unique name while while updating same product. Here is the code i have used for updating. public function update(Request $request, $id) { $product = Product::find($id); $this->validate($request, [ 'product_name'=> 'unique:products,product_name,'.$product->id , ]); $product->product_name = Input::get('product_name'); $product->product_unit_price = Input::get('product_unit_price'); $product->save(); return Redirect::to('products'); } from Laravel Questions and Answers https://laravelquestions.com/php/ignore-unique-validation-while-update-data/ via Lzo Media

QueryException SQLSTATE[HY000] [2002] Connection refused [duplicate] - development

QueryException SQLSTATE[HY000] [2002] Connection refused [duplicate] This question already has an answer here: Mysql connection refused on localhost 1 answer Not able to connect to database using laravel PHP version: 7.1.10 MAC OSX Error: Whoops, looks like something went wrong. (2/2) QueryException SQLSTATE[HY000] [2002] Connection refused (SQL: SELECT * FROM project_categories WHERE status='A') in Connection.php (line 647) at Connection->runQueryCallback(object(Expression), array(), object(Closure)) in Connection.php (line 607) at Connection->run(object(Expression), array(), object(Closure)) in Connection.php (line 326) at Connection->select(object(Expression)) in DatabaseManager.php (line 324)` ENV SETTINGS APP_NAME=Somesite APP_ENV=local APP_KEY=base64:hFfau6WVxgBJ7GCmvnOK+GZd9/MuIy03zAqNCO8VTO8= APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=somesite DB_USERNAME=root D...

Empty model in Eloquent Global scope? - development

Empty model in Eloquent Global scope? I am trying to determine if a user has the ability to update a model in a global scope, but I am using permission prefixes that I normally get through a relation. The apply code is as follows: public function apply(Builder $builder, Model $model) { $user = getUser(); if ($user === null || $user->cannot('update', $model)) { $builder->where('active', '=', 1); } } When I dd($model) the model is not actually instantiated so when I do my update permission check in my policy: public function update(User $user, Item $item) { return $user->hasAnyPermission(['edit-things', $this->prefix($item) . "-edit-item"]); } Where the prefix function looks like: private function prefix(Item $item = null) { if ($item !== null) { return $item->parentRelation->roles_permission_prefix; } $parentRelation= ParentRelation::findOrFail(request('parent_relati...

Laravel routes are not found in 000webhost - development

Laravel routes are not found in 000webhost I’m building a simple blog for my personal projects with Laravel 5.4.36. I have uploaded it to 000webhost . The problem is everytime I`m trying to sign up or sign in, it is saying, The requested URL was not found on this server Here is the URL that is shown during this error, https://myprojectblog.000webhostapp.com/signUp Here ‘signUp’ or ‘signIn’ are provided in the routes file which are given below, Route::post('/signUp', [ 'uses'=>'UserController@postSignUp', 'as'=>'signUp' ]); Route::post('/signIn', [ 'uses'=>'UserController@postSignIn', 'as'=>'signIn' ]); The sign up form is given below, <div class="signUp"> <label>Sign Up</label></br> <form action="" method="POST" name="signUp" id="signUp"> <label id=...