Laravel Voyager create user fails to prompt and aborts - laravel

I am trying to create a Voyager user. I enter php artisan voyager:admin user#email.com --create in a Windows command window. It aborts because the enter user prompt did not wait for my input.
What do I need to do to make it wait for an answer? I am using Laravel 8.

This is a bug in PHP 7.4.0 on Windows so you either update to 7.4.1 or downgrade to 7.3.

I don't want to downgrade or upgrade the PHP version. So I simply solved the problem by executing these queries on the Database directly.
Password is: "password"
CREATE TABLE IF NOT EXISTS `admins` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`role_id` bigint(20) UNSIGNED DEFAULT NULL,
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`avatar` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT 'users/default.png',
`password` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`remember_token` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`settings` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `admins_email_unique` (`email`),
KEY `admins_role_id_foreign` (`role_id`)
)
INSERT INTO `admins` (`id`, `role_id`, `name`, `email`, `avatar`, `password`,
`remember_token`, `settings`, `created_at`, `updated_at`) VALUES
(1, 1, 'Admin', 'admin#admin.com', 'users/default.png',
'$2y$10$QndDoDX9ccomsjWXvWu1.uRFA5iGMEBiq1A5NcdrtvxgBDW4IIsAq', NULL, NULL,
'2023-01-09 21:40:59', '2023-01-09 21:40:59');
Admin has the role_id 1 and granted all permission by default. But If you face the permission problem, sort it out by visiting the permission_role table.

Related

Sort By with function on collection laravel

I would like some help on this, i have a table like this
CREATE TABLE IF NOT EXISTS `items` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`code` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
`unitPrice` decimal(8,2) NOT NULL,
`quantity` int(11) NOT NULL,
`totalSold` int(11) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
and after using DB::table('items')->get();
i would like to get the same result as if i run this sql command
"select `code`,(`unitPrice`*(`quantity`+`totalSold`)) as totalEarnIfsold from `items` order by `totalEarnIfsold` desc"
what i have been able to achieve without success ofc is this:
$items_all->sortBy([
$totalEarnIfsold= fn ($a) => $a->unitPrice *($a->quantity+$a->totalSold),
['totalEarnIfsold', 'desc'],
]);
So i need your help if you may ofc, and thanks
You can do in following way
First you need to calculate totalEarnIfsold with map function and after that you can easily sort with value.
$items_all = $items_all->map(function($item) {
$item->totalEarnIfsold = $item->unitPrice *($item->quantity + $item->totalSold);
return $item;
})->sortByDesc('totalEarnIfsold');

Error on SQLite migrations after upgrade Laravel 5.8 to 6.2

I need some help!
I have an API built in laravel 5.8, i am upgrading the platform to 6.2.
After all changes in configuration files and some scripts php, all my tests witch run the migrations on SQLite is broken.
The following error is displayed:
SQLSTATE[HY000]: General error: 1 no such collation sequence: utf8_general_ci (SQL: CREATE TABLE events (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, event VARCHAR(255) NOT NULL COLLATE BINARY, description CLOB DEFAULT NULL COLLATE BINARY, invitation CLOB DEFAULT NULL COLLATE BINARY, sale CLOB DEFAULT NULL COLLATE BINARY, information CLOB DEFAULT NULL COLLATE BINARY, city VARCHAR(255) NOT NULL COLLATE BINARY,
location VARCHAR(255) NOT NULL COLLATE BINARY, date_start DATE NOT NULL, time_start TIME NOT NULL, date_end DATE DEFAULT NULL, flyer CLOB DEFAULT NULL COLLATE BINARY, atv BOOLEAN DEFAULT '1', created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, location_map VARCHAR(255) DEFAULT NULL COLLATE utf8_general_ci --IFRAME com a localização do evento.
My intention is update to 7.x after resolve all issues on 6.2.
In the migrations, was enough to remove the collation option from the fields. Example:
Initially this way:
$table->string('field', 255)->charset('utf8')->collation('utf8_general_ci')->change();
The solution was as follows:
$table->string('field', 255)->charset('utf8')->change();
Removing this option will not force a collation not accepted by SQLite.

Laravel - Eloquent query to display Quiz Result

I am trying to write a query in my controller to display Quiz result for students. I have these tables
CREATE TABLE IF NOT EXISTS `quizz_question` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`topic` varchar(1000) COLLATE utf8_unicode_ci NOT NULL,
`question_code` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`answer1` varchar(100) COLLATE utf8_unicode_ci NULL,
`answer2` varchar(100) COLLATE utf8_unicode_ci NULL,
`answer3` varchar(100) COLLATE utf8_unicode_ci NULL,
`answer4` varchar(100) COLLATE utf8_unicode_ci NULL,
`topic` varchar(1000) COLLATE utf8_unicode_ci NOT NULL,
`correct_answer` varchar(100) COLLATE utf8_unicode_ci NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=10 ;
CREATE TABLE IF NOT EXISTS `quizz_attempt` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`student_code` varchar(1000) COLLATE utf8_unicode_ci NOT NULL,
`answer` varchar(100) COLLATE utf8_unicode_ci NULL,
`question_code` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=10 ;
The two tables became these two model classes: QuizzQuestion and QuizAttempt.
In quizz_attempt, if a student select an answer (answer), it will take answer and question_code in quizz_attempt and compare with quizz_question.
quizz_attempt.answer = 1 then it will choose the content in answer1 as correct answer
quizz_attempt.answer = 2 then it will choose the content in answer2 as correct answer
quizz_attempt.answer = 3 then it will choose the content in answer3 as correct answer
quizz_attempt.answer = 4 then it will choose the content in answer4 as correct answer
public function gameQualifiers(Request $request)
{
$revenuedetails = DB::table('quizz_attempt as g')
->select(
'g.student_code',
'g.answer'
)
->orderByRaw('g.created_at DESC');
}
I know I need to join the two tables for the result. I started the code in my controller, but don't know how to complete it. i want to write a query to display list of students who choose correct answers
The quiz attempt should have the quizz_question_id as a Foreign Key. This will make it easier down the line to have the two connected.
You can set up two models to match your database tables: QuizzQuestion and QuizzAttempt. You can set up Foreign Keys like so:
QuizzAttempt.php
public function quizzQuestion()
{
return $this->belongsTo('App\QuizzQuestion');
}
And QuizzQuestion.php
public function quizzAttempts()
{
return $this->hasMany('App\QuizzQuestion');
}
So now, you want to get all of the attempts where the answer is correct - you are looking at an instance of QuizzQuestion, e.g.
$question = QuizzQuestion::find(1); // first question
$correctResults = QuizzAttempts::where('quizz_question_id', $question->id)
->where('answer', $question->correct_answer)
->pluck('student_code');`
Now you have all the student codes of the students that got the correct answers.
*** Update
If you cannot change the structure of the tables, you can run the following query:
// 1) find the question you want the answers for
$question = QuizzQuestion::find(1);
// 2) retrieve the correct results
$correctResults = QuizzAttempts::where('question_code', $question->question_code)
->where('answer', $question->correct_answer)
->pluck('student_code');`

Joomla migration issue

I have transferred my website to a new server after updating the files and database I am getting this issue
Table 'jimcorbe_jimcorbe.xpivg_session' doesn't exist SQL=INSERT INTO xpivg_session (session_id, client_id, time) VALUES ('18f0b96cfc5e1cb723b8405137ff36a6', 0, '1427709725')
I am very new to joomla so could not understand what it means. Can anyone provide me with the solution to get back my website live.
During the migration, it's possible that database table prefixes have changed.
Open PhpMyAdmin and look for the session table. If it doesn't exist, run the following SQL command:
CREATE TABLE IF NOT EXISTS `xpivg_session` (
`session_id` varchar(200) NOT NULL DEFAULT '',
`client_id` tinyint(3) unsigned NOT NULL DEFAULT '0',
`guest` tinyint(4) unsigned DEFAULT '1',
`time` varchar(14) DEFAULT '',
`data` mediumtext,
`userid` int(11) DEFAULT '0',
`username` varchar(150) DEFAULT '',
`usertype` varchar(50) DEFAULT '',
PRIMARY KEY (`session_id`),
KEY `whosonline` (`guest`,`usertype`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

codeigniter join problem

Hello all i have a problem that when i try to join my comment table it show nothing
here is my code
$this->db->select('*,users.profil_billed as profil_billed, forum_traad.id as traad_id');
$this->db->from('forum_traad');
$this->db->join('users', 'forum_traad.brugernavn = users.username');
$this->db->where('forum_traad.fk_forum_kategori', $id);
$this->db->join('forum_kommentare', 'forum_traad.id = forum_kommentare.fk_forum_traad');
$this->db->where('forum_kommentare.fk_forum_traad', 'forum_traad.id');
$this->db->order_by("forum_traad.id", "DESC");
its then i put this in it show nothing, and i dont know why.. do i need some left join, right join etc.? i have try all of it :d
$this->db->join('forum_kommentare', 'forum_traad.id = forum_kommentare.fk_forum_traad');
$this->db->where('forum_kommentare.fk_forum_traad', 'forum_traad.id');
kommentare = comments
traad = thread
brugernavn = username
kategori = categori
its danish,
sorry my bad english hope some one can help me out
my database structure is this and im using mysql
CREATE TABLE `forum_kategori` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`kategori` text NOT NULL,
`beskrivelse` mediumtext NOT NULL,
`godkendt` varchar(4) NOT NULL DEFAULT 'ja',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
CREATE TABLE `forum_kommentare` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fk_forum_traad` int(11) NOT NULL,
`brugernavn` text NOT NULL,
`indhold` mediumtext NOT NULL,
`dato` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`time` text NOT NULL,
`godkendt` varchar(4) NOT NULL DEFAULT 'ja',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=28;
CREATE TABLE `forum_traad` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`overskrift` text NOT NULL,
`indhold` mediumtext NOT NULL,
`fk_forum_kategori` int(11) NOT NULL,
`brugernavn` text NOT NULL,
`dato` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`godkendt` varchar(4) NOT NULL DEFAULT 'ja',
`time` text NOT NULL,
`status` varchar(8) NOT NULL DEFAULT 'aaben',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(80) NOT NULL,
`password` text NOT NULL,
`kon` varchar(5) NOT NULL,
`alder` text NOT NULL,
`hood` varchar(4) DEFAULT NULL,
`fornavn` varchar(60) DEFAULT NULL,
`efternavn` varchar(100) DEFAULT NULL,
`city` text,
`ip` varchar(20) DEFAULT NULL,
`level` text,
`email` text,
`point` int(11) NOT NULL,
`oprettet` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`fritekst` mediumtext NOT NULL,
`profil_billed` text NOT NULL,
`online` varchar(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=31;
and it return nothing and no errors it only show a message i have done with a else statement that said "there is no threads on this categori", i have try with left join, right join inner join full join, ye all of it :S
You should try using a left join on your joins and work from there. If that doesn't work then there isn't a link between the tables.
Try this code:
$this->db->select('*,users.profil_billed as profil_billed, forum_traad.id as traad_id');
$this->db->from('forum_traad');
$this->db->join('users', 'forum_traad.brugernavn = users.username');
$this->db->join('forum_kommentare', 'forum_traad.id = forum_kommentare.fk_forum_traad');
$this->db->where('forum_traad.fk_forum_kategori', $id);
$this->db->order_by("forum_traad.id", "DESC");
You can use after $this->db->get() the
print $this->db->last_query();
and check what's wrong.

Resources