MakeLike https://melikeke.sakura.ne.jp/malike/intro
Use Python's Mecab to generate "like sentences" from various teacher data ・ Generated from category ・ Generated from a file ・ Generated from direct input Teacher data can be specified from the three patterns of.
・ Generated from category ・ Generated from a file ・ Generated from direct input
Member registration Login Member registration notification reset Password
Sakura server
Laravel
Make the layout part common in Laravel's Blade template http://cly7796.net/wp/php/to-a-common-layout-in-blade-template-of-laravel/
How to implement a quick login function in Laravel https://php-junkie.net/framework/laravel/login/
When "Command" make: auth "is not defined." Appears https://qiita.com/daisu_yamazaki/items/a914a16ca1640334d7a5
[User authentication with Laravel7_8] Authenticate email when changing email address https://qiita.com/crosawassant/items/018b29ab770c0a373bc9
Let's examine the behavior of Laravel's standard Authentication (Auth) https://qiita.com/zaburo/items/9fcf0f4c771e011a4d35
Email notifications and Slack notifications are possible by either of the following methods
Laravel If you read this, you can set Laravel events and listeners https://reffect.co.jp/laravel/laravel-event-listener#i-8
Google Analytics Receive alerts from Google Analytics https://www.ad-market.jp/column/2020/04/20200420.html
Set up Laravel's email feature to send password reset emails.
"MailTrap" during local development In the production environment, we set the SMTP of "Sakura Server" and confirmed the communication.
E-mail transmission test with Laravel mail Trap Memorandum https://qiita.com/ryomaDsakamoto/items/e9d3a2c258dbfc66c524
Set the SMTP of Sakura server to the SMTP server of Laravel https://laraweb.net/tutorial/1265/
Try using the sophisticated "Laravel" email sending function https://liginc.co.jp/369690
Laravel5.7: Send Japanese password reset email https://qiita.com/sutara79/items/0ea48847f5565aacceea
When setting Japanese in Laravel, You can adapt the settings by writing in ja.json.
/resources/lang/ja.json
{
"Click link below and reset password.": "Please access the URL below and reset your password.",
"If you did not request a password reset, no further action is required.": "If you don't know this email, just delete it.",
}
blade.php
<p>
{{ __('Click link below and reset password.') }}<br>
{{ __('If you did not request a password reset, no further action is required.') }}
</p>
Actual display
The category pull-down makes the choices of "Category 2" change in association with "Category 1".
・ When category 1 is "lyrics"
・ When category 1 is "novel"
category1.id = category2.parent_id
categori1
categori2
How to make a parent-child select box like category / subcategory in laravel5.1 https://www.messiahworks.com/archives/12202
Set the path of teacher data to be read by Storage based on the value specified in the category.
contoloer.php
$input = $request->input();
$category1 = Arr::get($input, 'category1');
$category2 = Arr::get($input, 'category2');
$path = 'public/constText/';
$path .= $category1 . '/';
$path .= $category2 . '.txt';
Structure of constText
Use Laravel's Storage feature to implement the upload process. This time, the extension is set as follows to limit it to text data only. ·TXT ・ Csv ・ Xls ・ Xlsx
reference Detailed explanation on how to upload files with Laravel https://reffect.co.jp/laravel/how_to_upload_file_in_laravel
I tried to summarize the operation of files and directories using Storage in Laravel https://qiita.com/t1k2a/items/50081988363cf2fa1bca
"Generate from file" is executed in the above flow, but "Generate from direct input" is also executed by utilizing the Storage function.
Generation flow from direct input Save the value of textarea as a text file in Storage Below, the same process as "Generate from file"
Python The automatically generated part by MeCab is summarized in the following article.
reference Automatically generated catch phrase [Python] https://qiita.com/SyogoSuganoya/items/ba542f686104811e2d6b
In a firing event such as input button implemented in Laravel Allows you to implement Python.
Use PHP's exec function to execute Python.
reference PHP and Python integration from scratch on Laravel https://qiita.com/SwitchBlade/items/96ed4ea425ef2d758f71
PHP --Summary of the relationship between exec () error handling and standard error output https://qiita.com/smd8122/items/65b552f1d53bfb7fad9a
Ajax
Creating a dynamic comment viewing screen using Laravel and Ajax https://www.merges.co.jp/archives/1980
Use Ajax (jQuery) with Laravel https://pointsandlines.jp/server-side/php/laravel-ajax
Asynchronous processing by passing values with Laravel and Ajax. https://niwacan.com/1619-laravel-ajax/
Ajax is used to display the "generated text" area after pressing the generate button. Display the PHP exec function "\ $ outputs" in the generated text. $ outputs contains the printed string while running Python
controller.php
exec($command , $outputs, $return_var);
$data = [
'outputs' => $outputs,
'return_var' => $return_var,
];
return response()->json($data);
pythonCall.js
var params = {
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: url,
method: 'post',
dataType: 'json',
data: paramData,
//Runs until the request is complete
beforeSend: function(){
$('h3').text('Loading');
$("input").attr("disabled","true");
$('.wrapper .button').addClass('pushed');
$('.heart-check').prop('checked', false); //Remove all checked items
}
};
$.ajax(
params
).done(function( data ) {
//Initialization of generated text
$('input.sentence').val('');
//Input of generated sentences
for(var i = 0; i < data.outputs.length && i < 5; i++){
$('input.sentence').eq(i).val(data.outputs[i]);
}
}
Favorite registration of generated sentences and Manage your favorite texts on My Page
The favorite function uses Ajax and processes asynchronously.
controller.php
//Display of list screen
public function index(Request $request) {
$posts = Favorite_sentence::where('user_id', $request->user()->id) //$Get posts by user
->orderBy('created_at', 'desc') //Arrange posts in chronological order
->paginate(10); //Pagination;
return view('user.mypage', [
'posts' => $posts, // $Pass the article written by user to view
]);
}
//Click on the heart symbol(Register or delete)
public function ajaxlike(Request $request) {
// $user_id = $request->user()->id;
$user_id = Auth::user()->id;
$post_id = $request->post_id;
$sentence = $request->sentence;
$like = new Favorite_sentence;
$exist = Favorite_sentence::where('id', $post_id)->get();
$isExist = $exist->isEmpty();
if ($isExist) {
//Create a new record in the likes table if empty (not yet liked)
$like = new Favorite_sentence;
$like->user_id = $user_id;
$like->sentence = $sentence;
$like->save();
$post_id = $like->id;
$command = 'insert';
} else {
//Confirmation of the existence of your favorite phrase
Favorite_sentence::findOrFail($post_id);
//Delete records in likes table
$like = Favorite_sentence::where('id', $post_id)
->delete();
$command = 'delete';
}
$data = [
'user_id' => $user_id,
'post_id' => $post_id,
'sentence' => $sentence,
'command' => $command,
];
//Return the argument value to ajax with the following description
return response()->json($data);
}
likeSentence.js
var like = $('.heart-label');
var likePostId;
var sentence;
like.on('click', function () {
var $this = $(this);
//Favorite sentence ID
likePostId = $this.parent().parent().find(".sentence").attr('data-postid');
//Favorite sentences
sentence = $this.parent().parent().find(".sentence").val();
//Favorite text is blank
if (!sentence) {
return;
}
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: '/ajaxlike',
type: 'POST',
data: {
'post_id': likePostId ,
'sentence': sentence ,
},
}).done(function (data) {
if(data.command = 'insert') {
$this.parent().parent().find(".sentence").attr('data-postid', data.post_id);
}
});
Use "Sakura Server" in production environment
Output the result of morphological analysis with Mecab to a WEB browser compatible with Sakura server / UTF-8 https://qiita.com/Jshirius/items/ac3ca66a2d5262b98b58
Install mecab on Sakura shared server and call it from python https://qiita.com/Jshirius/items/3a067486e2a693544c32
A story that I had a hard time trying to call python with the exec function from php on the X server https://hazukei.com/1259/
If that doesn't work, compare "site-packages" between terminal execution and PHP execution.
import site
site.USER_SITE
Add diffs to make installed packages executable
import sys
sys.path.append('vendor\Lib\site-packages')
reference Install Python module on Sakura rental server https://emptypage.jp/notes/sakura-python.html
An active engineer explains how to check and set the installation destination of the Python module [for beginners] https://techacademy.jp/magazine/46510
Laravel [0001] SSH into Sakura's rental server and install Laravel https://www.failibere.com/development_memo/lalavel/0001
Make a symbolic link to storage on the Sakura server https://blog.hiroyuki90.com/articles/laravelで作成したwebアプリをレンタルサーバに公開する/
Recommended Posts