1548987627
We’ll build a simple monitor that will track the number of people that followed us on specific dates, using Medium as the use case. This is just a bare prototype and can be done for any other social media or networking platform.
In the end, we should have something like this:
To achieve this, we will use the node-imap package. The two major protocols for handling emails are IMAP (Internet Messaged Access Protocol) and POP (Post office protocol). IMAP is preferred, because it always syncs with the mail server, hence the changes made on the mail client will appear immediately on the webmail inbox.
Firstly, install the necessary packages.
npm i --save node-imap apollo-server mailparser
Now you can define the types and resolver and then run the apollo server.
const {ApolloServer, gql} = require('apollo-server') const typeDefs = gql` type User { email: String! password: String! } type Mutation { imapMutation(email: String!, password: String!): User! } ` const resolvers = { Mutation:{ imapMutation: (parent, args) => {} } } const server = new ApolloServer({typeDefs, resolvers}) server.listen({port: process.env.PORT || 4000}).then(({url})=>{ console.log(`Server started at ${url}, \n Unai Way ✈️ ✈️ ✈️` ) })
A ‘User’ type that has the email and password string types as its schema has been defined, and a mutation called ‘imapMutation’ which receives the email and password from the user and then returns a response with the User type.
The resolver handles the mutation, and then you can work with the arguments sent from the client.
Now you can run the server.
You can then import the node-imap and mailparser modules. The mailparser module will be used to receive the mail responses as JSON.
const Imap = require('imap') const simpleParser = require('mailparser').simpleParser
You are going to create a ‘connectImap’ function that will handle our IMAP functionality. From the node-imap documentation, you can get the skeleton of how the module works, and then copy and paste it into the code. It basically works with callbacks and emitters, so we’ll wrap it in a promise.
You should have something like this.
//Create an array to hold the graphPoints let graphPoints = [];async function connectToImap(user,password) { let resolveGraph = new Promise((resolve,reject)=>{ const imap = new Imap({ user: user, password: password, host: 'imap.gmail.com', port: 993, tls: true }) function openInbox(cb) { imap.openBox('INBOX', true, cb) } imap.once('ready', function() { openInbox(function(err, box) { if (err) throw new Error('Invalid Login. Please Try again.') f.on('message', function(msg, seqno) { msg.on('body', function(stream, info) { let buffer = '' stream.on('data', function(chunk) { buffer += chunk.toString('utf8') }) }) }) f.once('error', function(err) { reject(new Error('Fetching results failed')) }) f.once('end', function() { console.log('Done fetching all messages!') imap.end() }) }) }) }) imap.once('error', function(err) { reject(new Error('Failed Imap connection')) }) imap.once('end', function() { console.log('Connection ended') }) imap.connect() }) return await resolveGraph }
When the ‘ready’ event is called, we connect to our mail, and then we can search for messages. So, we’ll search for emails from the medium account that handles followers (noreply@medium.com).
Our ‘ready’ event should look like this.
imap.once(‘ready’, function() {
//Open Inbox
openInbox(function(err, box) {
if (err) throw new Error(‘Invalid Login. Please Try again.’)
//Search for mails sent from the medium account
imap.search([[‘FROM’,
‘noreply@medium.com’,
]], (err,result) =>{
//Get the headers from the mail
var f = imap.fetch(result, {
bodies: [‘HEADER.FIELDS (FROM SUBJECT DATE)’],
struct: true
})
f.on(‘message’, function(msg, seqno) {
msg.on(‘body’, function(stream, info) {
let buffer = ‘’
stream.on(‘data’, function(chunk) {
buffer += chunk.toString(‘utf8’)
simpleParser(buffer).then(parsed => {
//Check if the subject of each mail had a ‘started following you’ substring
if(parsed.subject && parsed.subject.includes(‘started following you’)){
//Split the array to get the total number of followers, and remove empty spaces
let numberOfFollowers = parsed.subject.split(/,|and/).filter(v=>v!=’ ').length
//Handle the instance where the mail says ‘paschal and 3 others followed you’
if(/\d others/.test(parsed.subject)) {
let otherNumber = /\d/.exec(parsed.subject)
numberOfFollowers += (Number(otherNumber[0]) - 1)
}
//Create an object with the number of followers and the date
let dataPoint = {
numberOfFollowers: numberOfFollowers,
date: parsed.date
}
//Push to graphPoints array
graphPoints.push(dataPoint)
}
})
.catch(err =>{throw err})
})
})
})
f.once(‘error’, function(err) {
reject(new Error(‘Fetching results failed’))
})
f.once(‘end’, function() {
console.log(‘Done fetching all messages!’)
imap.end()
})
})
})
})
imap.once(‘error’, function(err) {
reject(new Error(‘Failed Imap connection’))
})imap.once('end', function() { console.log('Connection ended') resolve(graphPoints) }) imap.connect()
We search for emails where each subject contains a ‘started following you’ substring. Then, we split the arrays with either a comma or the conjunction ‘and’ to get the number of followers, and then handle cases like ‘Peter and 3 others started following you’. After splitting the string above, we will have an output:
[
‘Peter’,
‘3 others started following you’
]
The length of this array is 2, so we have two followers. If the subject contains ‘others’, we take the digit behind it and add to the length of the array, which is 5 and then we subtract 1 to get rid of the ‘3 others started following you’ string. This leaves us with 4.
Then, we resolve the promise when the ‘end’ event is fired (imap.once(‘end’)).
Since we will have to send the array to our apollo client, we will need to define the type of the ‘graphPoints’ array.
Our type definitions should look like this:
const typeDefs = gql`scalar Date # Make a type user type User { email: String! password: String! data: [Graph!] } type Graph { numberOfFollowers: Int! date: Date! } type Mutation { imapMutation(email: String!, password: String!): User! } `
We added the data key to the ‘User’ type, which will hold the ‘graphPoints’ value, and its type is an array of objects with the ‘Graph’ type.
Finally, we handle the resolver, which will get the email and the password of the user and then return the email and the data (graphPoints).
const resolvers = {
Mutation:{
imapMutation: (parent, args) => {
//Empty the array before each response
graphPoints = []
/*call the connectToImap function with the email and password
sent by the user */
return connectToImap(args.email,args.password)
.then(response =>{
const user = {
email: args.email,
data: response
}
//Send the response
return user
})
.catch(error =>{
return new Error(‘Invalid Credentials. Please Try again.’)
})
}
}
}
If we log the user object, our structure should be something like this:
email: String,
data: [ { numberOfFollowers: 1, date: 2017-07-05T07:53:18.000Z },
{ numberOfFollowers: 1, date: 2017-07-07T19:34:57.000Z }
]
Now, we want to get the data sent from the server and plot the chart with the v-charts module.
But first, we install our dependencies.
npm install --save vue-chartjs vue-apollo apollo-client apollo-link-http apollo-cache-persist apollo-cache-inmemory graphql graphql-tag moment
I know what you’re thinking — that’s a lot of dependencies. If you have troubles setting up a Vue project, you can find out how to do that here. We should also include vuetify and the vue-router if we want to style the project and create additional routes.
In our ‘src’ folder, we can create a ‘config’ folder. The structure should look like this:
|src
|config
-graphql.js
-index.js
-LineChart.js
|pages
-login.vue
|router
-index.js
App.vue
main.js
We will have to set up our graphql client in the src/config/index.js file.
import {ApolloClient} from ‘apollo-client’
import {HttpLink} from ‘apollo-link-http’
import {InMemoryCache} from ‘apollo-cache-inmemory’
import {CachePersistor} from ‘apollo-cache-persist’const httpLink = new HttpLink({ uri:"http://localhost:4000" }) export const cache = new InMemoryCache() const apolloClient = new ApolloClient({ link: httpLink, cache: cache }) export const persistor = new CachePersistor({ cache, storage: window.localStorage }) export default apolloClient
Make sure the uri is on the same port as your apollo server, by default the apollo server runs on port 4000. Our apollo client is then set up with the httpLink and the cache.
The src/config/graphql.js file should look like this:
import gql from ‘graphql-tag’export const IMAP_MUTATION = gql `mutation imapMutation($email: String!, $password: String!) { imapMutation( email: $email, password: $password ){ email data{ numberOfFollowers date } } }`
This query will submit the email and the password of the user to the imapMutation and then get the email and the data(graphPoints) from the apollo server.
Then, we create our chart component in the src/config/LineChart.js file. We can use charts ranging from bar charts to histograms. A line chart was used in this example.
import {Line, mixins} from ‘vue-chartjs’
const {reactiveProp} = mixinsexport default { extends: Line, mixins: [reactiveProp], props:['options'], mounted(){ this.renderChart(this.chartData,this.options) } }
We can import the ‘vue-apollo’ package in our main.js file and include the apolloProvider when initializing the app.
import Vue from ‘vue’
import ‘./plugins/vuetify’
import router from ‘./router/index’
import App from ‘./App.vue’
import Vuetify from ‘vuetify/lib’
import ‘vuetify/dist/vuetify.min.css’;//Graphql import apolloClient from './config/index' import VueApollo from 'vue-apollo' Vue.use(VueApollo) Vue.use(Vuetify) //apolloProvider const apolloProvider = new VueApollo({ defaultClient: apolloClient }) Vue.config.productionTip = false new Vue({ el: "#app", template: '<App/>', router, apolloProvider, components: {App}
})Finally, we will set up the src/pages/login.vue file, which we should have configured as the component for the default home route ‘/’ in the src/router/index.js file.
<template>
<div>
<div v-show=“!graphReady”>
<v-form
lazy-validation
v-model=“valid”
ref=“form”
>
<v-text-field
v-model=“email”
label=“Email”
required
></v-text-field>
<v-text-field
v-model=“password”
type=“password”
label=“Password”
required
></v-text-field>
<v-btn
:disabled=“!valid”
@click=“signup”
>
submit
</v-btn>
</v-form>
</div>
<div v-show=“graphReady”>
<h1>Hey <span v-if=“responseMail”>{{responseMail.email}},</span></h1><line-chart :chart-data="graphPoints" :options="options" /> </div> </div> </template> <script> import {IMAP_MUTATION} from '../config/graphql' import LineChart from '../config/LineChart.js' import apolloClient from '../config/index' import moment from 'moment' import gql from 'graphql-tag' export default { components: { LineChart }, data(){ return { valid: true, email: null, password: null, graphReady: false, responseMail: null, options:{ legend:{ display: false }, responsive: true, maintainAspectRatio: false, scales:{ xAxes:[{ gridLines:{ display: true, lineWidth: 1, drawBorder: false } }], yAxes:[{ gridLines:{ display: true, lineWidth: 3, drawBorder: false } }] } }, graphPoints: null } }, methods: { signup(){ if (this.$refs.form.validate()) { /*Include no-cache policy for this route to avoid caching passwords */ this.$apollo .mutate({ mutation: IMAP_MUTATION, variables:{ email: this.email, password: this.password } , fetchPolicy: 'no-cache' }) .then(response => { this.snackbar = false; this.responseMail = response.data.imapMutation; this.graphReady = true; return this.responseMail }) .then(res =>{ this.plotGraph() }) .catch(e =>{ console.log(e) }) } }, plotGraph(){ this.graphPoints = { labels:[], datasets: [ { label: 'Medium followers', borderColor: 'green', fill:false, lintTension: 0, pointBackgroundColor: 'red', data:[] } ] } if(this.responseMail){ this.responseMail.data.map(point =>{ this.graphPoints.labels.push(this.formatDate(point.date.split('T')[0])) this.graphPoints.datasets[0].data.push(point.numberOfFollowers) }) } }, formatDate(date){ return moment(date, 'YYYY-MM-DD').format('Do MMM YY') } } } </script>
So we created a basic form that accepts the email and password of the user and then send this data to the server through the signup() method. The plotGraph() method loops through the response(graphPoints) and pushes the dates to the labels array and the number of followers to the data array.
After styling using the ‘options’ object, we should have something like the screenshot shown during the introduction to this project.
You can still do more with your personal project, but the aim of this was to show how to work with the node-imap package, and how apollo works as a server and as a client. If you had any problems with this project, you can leave a comment or send a message on Twitter.
You can try the live version of this, or you could check out the repositories for the client and server applications on GitHub.
If you want to learn new technologies and frameworks, you can do so hereand if you learned anything at all, please do well to clap below.
So we created a basic form that accepts the email and password of the user and then send this data to the server through the signup() method. The plotGraph() method loops through the response(graphPoints) and pushes the dates to the labels array and the number of followers to the data array.
After styling using the ‘options’ object, we should have something like the screenshot shown during the introduction to this project.
You can still do more with your personal project, but the aim of this was to show how to work with the node-imap package, and how apollo works as a server and as a client. If you had any problems with this project, you can leave a comment or send a message on Twitter.
You can try the live version of this, or you could check out the repositories for the client and server applications on GitHub.
If you want to learn new technologies and frameworks, you can do so hereand if you learned anything at all, please do well to clap below.
I will like to thank Wes Wagner for his feedback in making this article.
Thanks!
By : Paschal
#node-js #vue-js #graphql
1658359680
O pacote Laravel Share permite que você gere dinamicamente botões de compartilhamento social de redes sociais populares para aumentar o engajamento de mídia social.
Isso permite que os visitantes do site compartilhem facilmente o conteúdo com suas conexões e redes de mídia social.
Neste tutorial, mostro como você pode adicionar links de compartilhamento social em seu projeto Laravel 8 usando o pacote Laravel Share.
Instale o pacote usando o compositor –
composer require jorenvanhocht/laravel-share
config/app.php
arquivo.Jorenvh\Share\Providers\ShareServiceProvider::class
em 'providers'
–'providers' => [
....
....
....
Jorenvh\Share\Providers\ShareServiceProvider::class,
];
'Share' => Jorenvh\Share\ShareFacade::class
em 'aliases'
–'aliases' => [
....
....
....
'Share' => Jorenvh\Share\ShareFacade::class,
];
Execute o comando -
php artisan vendor:publish --provider="Jorenvh\Share\Providers\ShareServiceProvider"
routes/web.php
arquivo.Código concluído
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PageController;
Route::get('/', [PageController::class, 'index']);
PageController
controlador.php artisan make:controller PageController
app/Http/Controllers/PageController.php
arquivo.index() – Crie um link de compartilhamento usando Share::page()
e atribua a $shareButtons1
. Da mesma forma, crie mais 2 links e atribua as variáveis.
Carregue index
a visualização e passe $shareButtons1
, $shareButtons2
, e $shareButtons3
.
Código concluído
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PageController extends Controller
{
public function index(){
// Share button 1
$shareButtons1 = \Share::page(
'https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Share button 2
$shareButtons2 = \Share::page(
'https://makitweb.com/how-to-make-autocomplete-search-using-jquery-ui-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram();
// Share button 3
$shareButtons3 = \Share::page(
'https://makitweb.com/how-to-upload-multiple-files-with-vue-js-and-php/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Load index view
return view('index')
->with('shareButtons1',$shareButtons1 )
->with('shareButtons2',$shareButtons2 )
->with('shareButtons3',$shareButtons3 );
}
}
Criar index.blade.php
arquivo na resources/views/
pasta.
Inclua Bootstrap, CSS de fonte incrível, jQuery e js/share.js. –
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
Adicionado CSS para personalizar links de compartilhamento social.
Exiba links de compartilhamento social usando –
{!! $shareButtons1 !!}
Da mesma forma, exiba outros 2 – {!! $shareButtons2 !!} e {!! $shareButtons3 !!}.
Código concluído
<!DOCTYPE html>
<html>
<head>
<title>Add social share button in Laravel 8 with Laravel Share</title>
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
<style>
#social-links ul{
padding-left: 0;
}
#social-links ul li {
display: inline-block;
}
#social-links ul li a {
padding: 6px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 1px;
font-size: 25px;
}
#social-links .fa-facebook{
color: #0d6efd;
}
#social-links .fa-twitter{
color: deepskyblue;
}
#social-links .fa-linkedin{
color: #0e76a8;
}
#social-links .fa-whatsapp{
color: #25D366
}
#social-links .fa-reddit{
color: #FF4500;;
}
#social-links .fa-telegram{
color: #0088cc;
}
</style>
</head>
<body>
<div class='container'>
<!-- Post 1 -->
<div class='row mt-5'>
<h2>Datatables AJAX pagination with Search and Sort in Laravel 8</h2>
<p>With pagination, it is easier to display a huge list of data on the page.</p>
<p>You can create pagination with and without AJAX.</p>
<p>There are many jQuery plugins are available for adding pagination. One of them is DataTables.</p>
<p>In this tutorial, I show how you can add Datatables AJAX pagination without the Laravel package in Laravel 8.</p>
<!-- Social Share buttons 1 -->
<div class="social-btn-sp">
{!! $shareButtons1 !!}
</div>
</div>
<!-- Post 2 -->
<div class='row mt-5'>
<h2>How to make Autocomplete search using jQuery UI in Laravel 8</h2>
<p>jQuery UI has different types of widgets available, one of them is autocomplete.</p>
<p>Data is loaded according to the input after initialize autocomplete on a textbox. User can select an option from the suggestion list.</p>
<p>In this tutorial, I show how you can make autocomplete search using jQuery UI in Laravel 8.</p>
<!-- Social Share buttons 2 -->
<div class="social-btn-sp">
{!! $shareButtons2 !!}
</div>
</div>
<!-- Post 3 -->
<div class='row mt-5 mb-5'>
<h2>How to upload multiple files with Vue.js and PHP</h2>
<p>Instead of adding multiple file elements, you can use a single file element for allowing the user to upload more than one file.</p>
<p>Using the FormData object to pass the selected files to the PHP for upload.</p>
<p>In this tutorial, I show how you can upload multiple files using Vue.js and PHP.</p>
<!-- Social Share buttons 3 -->
<div class="social-btn-sp">
{!! $shareButtons3 !!}
</div>
</div>
</div>
</body>
</html>
No exemplo, consertei os links, mas você pode configurá-los dinamicamente.
Personalize o design usando CSS e o número de ícones sociais visíveis usando o controlador.
Usando o pacote Laravel Share, você pode compartilhar links para –
Fonte: https://makitweb.com
1658363460
El paquete Laravel Share le permite generar dinámicamente botones para compartir en redes sociales populares para aumentar la participación en las redes sociales.
Estos permiten a los visitantes del sitio web compartir fácilmente el contenido con sus conexiones y redes sociales.
En este tutorial, muestro cómo puede agregar enlaces para compartir en redes sociales en su proyecto Laravel 8 usando el paquete Laravel Share.
Instale el paquete usando composer –
composer require jorenvanhocht/laravel-share
config/app.php
archivo.Jorenvh\Share\Providers\ShareServiceProvider::class
en 'providers'
–'providers' => [
....
....
....
Jorenvh\Share\Providers\ShareServiceProvider::class,
];
'Share' => Jorenvh\Share\ShareFacade::class
en 'aliases'
–'aliases' => [
....
....
....
'Share' => Jorenvh\Share\ShareFacade::class,
];
Ejecute el comando –
php artisan vendor:publish --provider="Jorenvh\Share\Providers\ShareServiceProvider"
routes/web.php
archivo.Código completado
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PageController;
Route::get('/', [PageController::class, 'index']);
PageController
controlador.php artisan make:controller PageController
app/Http/Controllers/PageController.php
archivo.index (): cree un enlace compartido usando Share::page()
y asigne a $shareButtons1
. Del mismo modo, cree 2 enlaces más y asígnelos a variables.
Cargue la index
vista y pase $shareButtons1
, $shareButtons2
y $shareButtons3
.
Código completado
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PageController extends Controller
{
public function index(){
// Share button 1
$shareButtons1 = \Share::page(
'https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Share button 2
$shareButtons2 = \Share::page(
'https://makitweb.com/how-to-make-autocomplete-search-using-jquery-ui-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram();
// Share button 3
$shareButtons3 = \Share::page(
'https://makitweb.com/how-to-upload-multiple-files-with-vue-js-and-php/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Load index view
return view('index')
->with('shareButtons1',$shareButtons1 )
->with('shareButtons2',$shareButtons2 )
->with('shareButtons3',$shareButtons3 );
}
}
Crear index.blade.php
archivo en resources/views/
carpeta.
Incluya Bootstrap, font-awesome CSS, jQuery y js/share.js. –
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
Se agregó CSS para personalizar los enlaces para compartir en redes sociales.
Mostrar enlaces para compartir en redes sociales usando –
{!! $shareButtons1 !!}
Del mismo modo, muestra otros 2 – {!! $shareButtons2 !!}, y {!! $compartirBotones3 !!}.
Código completado
<!DOCTYPE html>
<html>
<head>
<title>Add social share button in Laravel 8 with Laravel Share</title>
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
<style>
#social-links ul{
padding-left: 0;
}
#social-links ul li {
display: inline-block;
}
#social-links ul li a {
padding: 6px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 1px;
font-size: 25px;
}
#social-links .fa-facebook{
color: #0d6efd;
}
#social-links .fa-twitter{
color: deepskyblue;
}
#social-links .fa-linkedin{
color: #0e76a8;
}
#social-links .fa-whatsapp{
color: #25D366
}
#social-links .fa-reddit{
color: #FF4500;;
}
#social-links .fa-telegram{
color: #0088cc;
}
</style>
</head>
<body>
<div class='container'>
<!-- Post 1 -->
<div class='row mt-5'>
<h2>Datatables AJAX pagination with Search and Sort in Laravel 8</h2>
<p>With pagination, it is easier to display a huge list of data on the page.</p>
<p>You can create pagination with and without AJAX.</p>
<p>There are many jQuery plugins are available for adding pagination. One of them is DataTables.</p>
<p>In this tutorial, I show how you can add Datatables AJAX pagination without the Laravel package in Laravel 8.</p>
<!-- Social Share buttons 1 -->
<div class="social-btn-sp">
{!! $shareButtons1 !!}
</div>
</div>
<!-- Post 2 -->
<div class='row mt-5'>
<h2>How to make Autocomplete search using jQuery UI in Laravel 8</h2>
<p>jQuery UI has different types of widgets available, one of them is autocomplete.</p>
<p>Data is loaded according to the input after initialize autocomplete on a textbox. User can select an option from the suggestion list.</p>
<p>In this tutorial, I show how you can make autocomplete search using jQuery UI in Laravel 8.</p>
<!-- Social Share buttons 2 -->
<div class="social-btn-sp">
{!! $shareButtons2 !!}
</div>
</div>
<!-- Post 3 -->
<div class='row mt-5 mb-5'>
<h2>How to upload multiple files with Vue.js and PHP</h2>
<p>Instead of adding multiple file elements, you can use a single file element for allowing the user to upload more than one file.</p>
<p>Using the FormData object to pass the selected files to the PHP for upload.</p>
<p>In this tutorial, I show how you can upload multiple files using Vue.js and PHP.</p>
<!-- Social Share buttons 3 -->
<div class="social-btn-sp">
{!! $shareButtons3 !!}
</div>
</div>
</div>
</body>
</html>
En el ejemplo, arreglé los enlaces pero puedes configurarlos dinámicamente.
Personaliza el diseño usando CSS y la cantidad de íconos sociales visibles usando el controlador.
Usando el paquete Laravel Share puede compartir enlaces a –
Fuente: https://makitweb.com
1658370780
Le package Laravel Share vous permet de générer dynamiquement des boutons de partage social à partir de réseaux sociaux populaires pour augmenter l'engagement sur les réseaux sociaux.
Ceux-ci permettent aux visiteurs du site Web de partager facilement le contenu avec leurs connexions et réseaux de médias sociaux.
Dans ce didacticiel, je montre comment vous pouvez ajouter des liens de partage social dans votre projet Laravel 8 à l'aide du package Laravel Share.
Installez le package à l'aide de composer -
composer require jorenvanhocht/laravel-share
config/app.php
le fichier.Jorenvh\Share\Providers\ShareServiceProvider::class
dans 'providers'
-'providers' => [
....
....
....
Jorenvh\Share\Providers\ShareServiceProvider::class,
];
'Share' => Jorenvh\Share\ShareFacade::class
dans 'aliases'
-'aliases' => [
....
....
....
'Share' => Jorenvh\Share\ShareFacade::class,
];
Exécutez la commande -
php artisan vendor:publish --provider="Jorenvh\Share\Providers\ShareServiceProvider"
routes/web.php
le fichier.Code terminé
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PageController;
Route::get('/', [PageController::class, 'index']);
PageController
un contrôleur.php artisan make:controller PageController
app/Http/Controllers/PageController.php
le fichier.index() - Créez un lien de partage en utilisant Share::page()
et attribuez-le à $shareButtons1
. De même, créez 2 autres liens et affectez-les aux variables.
Charger la index
vue et passer $shareButtons1
, $shareButtons2
et $shareButtons3
.
Code terminé
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PageController extends Controller
{
public function index(){
// Share button 1
$shareButtons1 = \Share::page(
'https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Share button 2
$shareButtons2 = \Share::page(
'https://makitweb.com/how-to-make-autocomplete-search-using-jquery-ui-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram();
// Share button 3
$shareButtons3 = \Share::page(
'https://makitweb.com/how-to-upload-multiple-files-with-vue-js-and-php/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Load index view
return view('index')
->with('shareButtons1',$shareButtons1 )
->with('shareButtons2',$shareButtons2 )
->with('shareButtons3',$shareButtons3 );
}
}
Créer index.blade.php
un fichier dans resources/views/
le dossier.
Incluez Bootstrap, CSS font-awesome, jQuery et js/share.js. –
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
CSS ajouté pour personnaliser les liens de partage social.
Afficher les liens de partage social en utilisant –
{!! $shareButtons1 !!}
De même, affichez les autres 2 – {!! $shareButtons2 !!}, et { !! $shareButtons3 !!}.
Code terminé
<!DOCTYPE html>
<html>
<head>
<title>Add social share button in Laravel 8 with Laravel Share</title>
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
<style>
#social-links ul{
padding-left: 0;
}
#social-links ul li {
display: inline-block;
}
#social-links ul li a {
padding: 6px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 1px;
font-size: 25px;
}
#social-links .fa-facebook{
color: #0d6efd;
}
#social-links .fa-twitter{
color: deepskyblue;
}
#social-links .fa-linkedin{
color: #0e76a8;
}
#social-links .fa-whatsapp{
color: #25D366
}
#social-links .fa-reddit{
color: #FF4500;;
}
#social-links .fa-telegram{
color: #0088cc;
}
</style>
</head>
<body>
<div class='container'>
<!-- Post 1 -->
<div class='row mt-5'>
<h2>Datatables AJAX pagination with Search and Sort in Laravel 8</h2>
<p>With pagination, it is easier to display a huge list of data on the page.</p>
<p>You can create pagination with and without AJAX.</p>
<p>There are many jQuery plugins are available for adding pagination. One of them is DataTables.</p>
<p>In this tutorial, I show how you can add Datatables AJAX pagination without the Laravel package in Laravel 8.</p>
<!-- Social Share buttons 1 -->
<div class="social-btn-sp">
{!! $shareButtons1 !!}
</div>
</div>
<!-- Post 2 -->
<div class='row mt-5'>
<h2>How to make Autocomplete search using jQuery UI in Laravel 8</h2>
<p>jQuery UI has different types of widgets available, one of them is autocomplete.</p>
<p>Data is loaded according to the input after initialize autocomplete on a textbox. User can select an option from the suggestion list.</p>
<p>In this tutorial, I show how you can make autocomplete search using jQuery UI in Laravel 8.</p>
<!-- Social Share buttons 2 -->
<div class="social-btn-sp">
{!! $shareButtons2 !!}
</div>
</div>
<!-- Post 3 -->
<div class='row mt-5 mb-5'>
<h2>How to upload multiple files with Vue.js and PHP</h2>
<p>Instead of adding multiple file elements, you can use a single file element for allowing the user to upload more than one file.</p>
<p>Using the FormData object to pass the selected files to the PHP for upload.</p>
<p>In this tutorial, I show how you can upload multiple files using Vue.js and PHP.</p>
<!-- Social Share buttons 3 -->
<div class="social-btn-sp">
{!! $shareButtons3 !!}
</div>
</div>
</div>
</body>
</html>
Dans l'exemple, j'ai corrigé les liens mais vous pouvez les définir dynamiquement.
Personnalisez la conception à l'aide de CSS et du nombre d'icônes sociales visibles à l'aide du contrôleur.
En utilisant le package Laravel Share, vous pouvez partager des liens vers -
Source : https://makitweb.com
1658378100
Laravel Share 包可讓您從流行的社交網絡動態生成社交分享按鈕,以增加社交媒體的參與度。
這些允許網站訪問者輕鬆地與他們的社交媒體連接和網絡共享內容。
在本教程中,我將展示如何使用 Laravel Share 包在 Laravel 8 項目中添加社交分享鏈接。
使用 composer 安裝包——
composer require jorenvanhocht/laravel-share
config/app.php
文件。Jorenvh\Share\Providers\ShareServiceProvider::class
到'providers'
–'providers' => [
....
....
....
Jorenvh\Share\Providers\ShareServiceProvider::class,
];
'Share' => Jorenvh\Share\ShareFacade::class
到'aliases'
–'aliases' => [
....
....
....
'Share' => Jorenvh\Share\ShareFacade::class,
];
運行命令——
php artisan vendor:publish --provider="Jorenvh\Share\Providers\ShareServiceProvider"
routes/web.php
文件。完成的代碼
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PageController;
Route::get('/', [PageController::class, 'index']);
PageController
控制器。php artisan make:controller PageController
app/Http/Controllers/PageController.php
文件。index() –使用Share::page()
並分配給$shareButtons1
. 同樣,再創建 2 個鏈接並分配給變量。
加載index
視圖並通過$shareButtons1
、$shareButtons2
和$shareButtons3
。
完成的代碼
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PageController extends Controller
{
public function index(){
// Share button 1
$shareButtons1 = \Share::page(
'https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Share button 2
$shareButtons2 = \Share::page(
'https://makitweb.com/how-to-make-autocomplete-search-using-jquery-ui-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram();
// Share button 3
$shareButtons3 = \Share::page(
'https://makitweb.com/how-to-upload-multiple-files-with-vue-js-and-php/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Load index view
return view('index')
->with('shareButtons1',$shareButtons1 )
->with('shareButtons2',$shareButtons2 )
->with('shareButtons3',$shareButtons3 );
}
}
index.blade.php
在 文件夾中創建文件resources/views/
。
包括 Bootstrap、font-awesome CSS、jQuery 和 js/share.js。–
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
添加了 CSS 以自定義社交分享鏈接。
使用 - 顯示社交分享鏈接
{!! $shareButtons1 !!}
同樣,顯示其他 2 – {!! $shareButtons2 !!} 和 {!! $shareButtons3 !!}。
完成的代碼
<!DOCTYPE html>
<html>
<head>
<title>Add social share button in Laravel 8 with Laravel Share</title>
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
<style>
#social-links ul{
padding-left: 0;
}
#social-links ul li {
display: inline-block;
}
#social-links ul li a {
padding: 6px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 1px;
font-size: 25px;
}
#social-links .fa-facebook{
color: #0d6efd;
}
#social-links .fa-twitter{
color: deepskyblue;
}
#social-links .fa-linkedin{
color: #0e76a8;
}
#social-links .fa-whatsapp{
color: #25D366
}
#social-links .fa-reddit{
color: #FF4500;;
}
#social-links .fa-telegram{
color: #0088cc;
}
</style>
</head>
<body>
<div class='container'>
<!-- Post 1 -->
<div class='row mt-5'>
<h2>Datatables AJAX pagination with Search and Sort in Laravel 8</h2>
<p>With pagination, it is easier to display a huge list of data on the page.</p>
<p>You can create pagination with and without AJAX.</p>
<p>There are many jQuery plugins are available for adding pagination. One of them is DataTables.</p>
<p>In this tutorial, I show how you can add Datatables AJAX pagination without the Laravel package in Laravel 8.</p>
<!-- Social Share buttons 1 -->
<div class="social-btn-sp">
{!! $shareButtons1 !!}
</div>
</div>
<!-- Post 2 -->
<div class='row mt-5'>
<h2>How to make Autocomplete search using jQuery UI in Laravel 8</h2>
<p>jQuery UI has different types of widgets available, one of them is autocomplete.</p>
<p>Data is loaded according to the input after initialize autocomplete on a textbox. User can select an option from the suggestion list.</p>
<p>In this tutorial, I show how you can make autocomplete search using jQuery UI in Laravel 8.</p>
<!-- Social Share buttons 2 -->
<div class="social-btn-sp">
{!! $shareButtons2 !!}
</div>
</div>
<!-- Post 3 -->
<div class='row mt-5 mb-5'>
<h2>How to upload multiple files with Vue.js and PHP</h2>
<p>Instead of adding multiple file elements, you can use a single file element for allowing the user to upload more than one file.</p>
<p>Using the FormData object to pass the selected files to the PHP for upload.</p>
<p>In this tutorial, I show how you can upload multiple files using Vue.js and PHP.</p>
<!-- Social Share buttons 3 -->
<div class="social-btn-sp">
{!! $shareButtons3 !!}
</div>
</div>
</div>
</body>
</html>
在示例中,我修復了鏈接,但您可以動態設置它們。
使用 CSS 自定義設計,並使用控制器顯示社交圖標的數量。
使用 Laravel Share 包,你可以分享鏈接到 -
1658389080
Gói Laravel Share cho phép bạn tạo động các nút chia sẻ xã hội từ các mạng xã hội phổ biến để tăng mức độ tương tác trên mạng xã hội.
Những điều này cho phép khách truy cập trang web dễ dàng chia sẻ nội dung với các kết nối và mạng xã hội của họ.
Trong hướng dẫn này, tôi chỉ cách bạn có thể thêm liên kết chia sẻ xã hội trong dự án Laravel 8 của mình bằng cách sử dụng gói Laravel Share.
Cài đặt gói bằng trình soạn nhạc -
composer require jorenvanhocht/laravel-share
config/app.php
tệp.Jorenvh\Share\Providers\ShareServiceProvider::class
vào 'providers'
-'providers' => [
....
....
....
Jorenvh\Share\Providers\ShareServiceProvider::class,
];
'Share' => Jorenvh\Share\ShareFacade::class
vào 'aliases'
-'aliases' => [
....
....
....
'Share' => Jorenvh\Share\ShareFacade::class,
];
Chạy lệnh -
php artisan vendor:publish --provider="Jorenvh\Share\Providers\ShareServiceProvider"
routes/web.php
tệp.Mã đã hoàn thành
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PageController;
Route::get('/', [PageController::class, 'index']);
PageController
Bộ điều khiển.php artisan make:controller PageController
app/Http/Controllers/PageController.php
tệp.index () - Tạo một liên kết chia sẻ bằng cách sử dụng Share::page()
và gán cho $shareButtons1
. Tương tự, tạo thêm 2 liên kết và gán cho các biến.
Tải index
chế độ xem và vượt qua $shareButtons1
, $shareButtons2
và $shareButtons3
.
Mã đã hoàn thành
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PageController extends Controller
{
public function index(){
// Share button 1
$shareButtons1 = \Share::page(
'https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Share button 2
$shareButtons2 = \Share::page(
'https://makitweb.com/how-to-make-autocomplete-search-using-jquery-ui-in-laravel-8/'
)
->facebook()
->twitter()
->linkedin()
->telegram();
// Share button 3
$shareButtons3 = \Share::page(
'https://makitweb.com/how-to-upload-multiple-files-with-vue-js-and-php/'
)
->facebook()
->twitter()
->linkedin()
->telegram()
->whatsapp()
->reddit();
// Load index view
return view('index')
->with('shareButtons1',$shareButtons1 )
->with('shareButtons2',$shareButtons2 )
->with('shareButtons3',$shareButtons3 );
}
}
Tạo index.blade.php
tệp trong resources/views/
thư mục.
Bao gồm Bootstrap, CSS font-awesome, jQuery và js / share.js. -
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
Đã thêm CSS để tùy chỉnh các liên kết chia sẻ trên mạng xã hội.
Hiển thị các liên kết chia sẻ xã hội bằng cách sử dụng -
{!! $shareButtons1 !!}
Tương tự, hiển thị 2 - {!! $ shareButtons2 !!} và {!! $ shareButtons3 !!}.
Mã đã hoàn thành
<!DOCTYPE html>
<html>
<head>
<title>Add social share button in Laravel 8 with Laravel Share</title>
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Share JS -->
<script src="{{ asset('js/share.js') }}"></script>
<style>
#social-links ul{
padding-left: 0;
}
#social-links ul li {
display: inline-block;
}
#social-links ul li a {
padding: 6px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 1px;
font-size: 25px;
}
#social-links .fa-facebook{
color: #0d6efd;
}
#social-links .fa-twitter{
color: deepskyblue;
}
#social-links .fa-linkedin{
color: #0e76a8;
}
#social-links .fa-whatsapp{
color: #25D366
}
#social-links .fa-reddit{
color: #FF4500;;
}
#social-links .fa-telegram{
color: #0088cc;
}
</style>
</head>
<body>
<div class='container'>
<!-- Post 1 -->
<div class='row mt-5'>
<h2>Datatables AJAX pagination with Search and Sort in Laravel 8</h2>
<p>With pagination, it is easier to display a huge list of data on the page.</p>
<p>You can create pagination with and without AJAX.</p>
<p>There are many jQuery plugins are available for adding pagination. One of them is DataTables.</p>
<p>In this tutorial, I show how you can add Datatables AJAX pagination without the Laravel package in Laravel 8.</p>
<!-- Social Share buttons 1 -->
<div class="social-btn-sp">
{!! $shareButtons1 !!}
</div>
</div>
<!-- Post 2 -->
<div class='row mt-5'>
<h2>How to make Autocomplete search using jQuery UI in Laravel 8</h2>
<p>jQuery UI has different types of widgets available, one of them is autocomplete.</p>
<p>Data is loaded according to the input after initialize autocomplete on a textbox. User can select an option from the suggestion list.</p>
<p>In this tutorial, I show how you can make autocomplete search using jQuery UI in Laravel 8.</p>
<!-- Social Share buttons 2 -->
<div class="social-btn-sp">
{!! $shareButtons2 !!}
</div>
</div>
<!-- Post 3 -->
<div class='row mt-5 mb-5'>
<h2>How to upload multiple files with Vue.js and PHP</h2>
<p>Instead of adding multiple file elements, you can use a single file element for allowing the user to upload more than one file.</p>
<p>Using the FormData object to pass the selected files to the PHP for upload.</p>
<p>In this tutorial, I show how you can upload multiple files using Vue.js and PHP.</p>
<!-- Social Share buttons 3 -->
<div class="social-btn-sp">
{!! $shareButtons3 !!}
</div>
</div>
</div>
</body>
</html>
Trong ví dụ, tôi đã sửa các liên kết nhưng bạn có thể đặt chúng động.
Tùy chỉnh thiết kế bằng cách sử dụng CSS và số lượng biểu tượng xã hội có thể nhìn thấy bằng bộ điều khiển.
Sử dụng gói Chia sẻ Laravel, bạn có thể chia sẻ các liên kết đến -
Nguồn: https://makitweb.com