dhamkith/contactus

laravel 框架的 contact us 功能

dev-master 2020-08-03 16:19 UTC

This package is auto-updated.

Last update: 2024-09-06 21:18:59 UTC


README

contactus

安装

安装很简单,设置类似于其他 Laravel 包。

1. 通过 Composer 安装

首先,通过 Composer 引入包

composer require dhamkith/contactus

2. 定义服务提供者和别名

接下来,我们需要引入别名和服务提供者。

注意:此包支持 Laravel 5.5 的新 自动发现 功能,因此如果您正在使用 Laravel 5.5 项目,则安装已完成,您可以跳到第 3 步。

如果您正在使用 Laravel 5.0 - 5.4,则需要添加提供者和别名。在您的 config/app.php 文件中定义一个新的服务提供者

'providers' => [
	//  other providers

	Dhamkith\Contactus\ContactUsServiceProvider::class,
];

然后,我们想在相同的 config/app.php 文件中定义一个别名。

'aliases' => [
	// other aliases

	'Contact' => Dhamkith\Contactus\Facades\DhamkithContact::class,
];

3. 发布配置文件和其他资源(可选)

此配置文件允许您覆盖此包的默认设置以满足您的特定需求。它是可选的,并允许您设置

  • 设置 contactus 电子邮件 - "email" => "site email address"(可选),
  • URL 路径 - "path" => "dhamkith",
  • ContactUsController 的中间件 - "middleware_for_view" => "auth",
  • "auth" 是默认中间件。您可以根据需要覆盖此值,
  • 如果您的应用程序支持多种身份验证,则可以将其更改为 "auth:admin"

要在终端中生成配置文件和其他资源,请输入以下命令

php artisan vendor:publish --tag=contactus

这会生成

  • 配置文件在 config/dhamkith_contactus.php
  • 视图文件在 resources/views/vendor/contactus/contact.blade.php
  • 视图文件在 resources/views/vendor/contactus/index.blade.php
  • 视图文件在 resources/views/vendor/contactus/show.blade.php
  • 样式文件在 public/css/dhamkith-contactus.css
  • JavaScript 文件在 public/js/dhamkith-contactus.js

4. 迁移(可选)

使用 php artisan migrate 创建 contact_us 表

php artisan migrate

用法

此包易于使用。它提供了一些有用的视图。

  • contact.blade.php 视图用于显示联系我们表单,
  • index.blade.php 视图用于显示所有联系信息,
  • show.blade.php 视图用于显示信息,

1. 添加样式和 JavaScript 文件

将 dhamkith-contactus.css 样式表标签添加到 'app' 或其他布局的 head 部分中

<head>

<!-- Other code here -->
<link href="{{ asset('css/dhamkith-contactus.css') }}" rel="stylesheet">

</head>

将 dhamkith-contactus.js 脚本标签添加到 body 部分中

<body>
<!-- Other html code here  -->

<!-- scripts -->
<script src="{{ asset('js/dhamkith-contactus.js') }}" defer></script> 

</body>

2. 扩展视图

扩展视图 contact, index, show

示例:视图 contact resources/views/vendor/contactus/contact.blade.php

@extends('layouts.app')

@section('content')
<div id="dha-form" class="dha-col-4">
    <div class="dha-form-card">
        <div class="card-title dha-shadow-none m-t-40">
            <h1 class="dha-text-center">{{ __('Want to contact Us?') }}</h1>
            <p class="dha-text-center">Here are a few ways to get in touch with us.</p>
            @include('contactus::notify.message')
        </div>
        <div class="content dha-shadow-none">
            <form method="POST" action="{{ route('contactus.store') }}">
                @csrf

                <div class="dha-form-field">
                    <label>Name*</label>
                    <input type="text"
                           name="name"
                           id="name"
                           class="dha-form-input {{ $errors->has('name') ? ' is-danger' : '' }}"
                           value="{{ old('name')}}"
                           title="name" placeholder="enter your name" required autofocus>
                    @if ($errors->has('name'))
                        <p class="help is-danger" >{{ $errors->first('name') }}</p>
                    @endif

                </div>

                <div class="dha-form-field">
                    <label>E-Mail Address*</label>
                    <input type="email"
                           name="email"
                           id="email"
                           class="dha-form-input {{ $errors->has('email') ? ' is-danger' : '' }}"
                           value="{{ old('email')}}"
                           title="location email"
                           placeholder="enter your eMail Address" required autofocus>
                    @if ($errors->has('email'))
                        <p class="help is-danger" >{{ $errors->first('email') }}</p>
                    @endif

                </div>

                <div class="dha-form-field">
                    <label>Subject*</label>
                    <input type="text"
                           name="subject"
                           id="subject"
                           class="dha-form-input {{ $errors->has('subject') ? ' is-danger' : '' }}"
                           value="{{ old('subject')}}"
                           title="subject" placeholder="subject here" required autofocus>
                    @if ($errors->has('subject'))
                        <p class="help is-danger" >{{ $errors->first('subject') }}</p>
                    @endif

                </div>

                <div class="dha-form-field">
                    <label>Message*</label>
                    <textarea type="text"
                           name="message"
                           id="message"
                           class="dha-form-input dha-form-textarea {{ $errors->has('message') ? ' is-danger' : '' }}"
                           title="subject"
                           col="12"
                           row="6"
                           placeholder="message here" required autofocus>{{ old('name')}}</textarea>
                    @if ($errors->has('message'))
                        <p class="help is-danger" >{{ $errors->first('message') }}</p>
                    @endif

                </div>

                <button type="submit" class="dha-fullwidth-btn"><span class="dha dha-paper-plane m-r-5"></span> send</button>

            </form>
        </div>
    </div>
</div>
@endsection

3. 使用包路由

包路由的名称是

显示所有存储联系信息的 contactus.lists
{{ route('contactus.lists') }}
获取联系我们的 contactus.create
{{ route('contactus.create') }}
显示单个信息 contactus.show
{{ route('contactus.show') }}

贡献

我鼓励您为此包做出贡献,以改进它并使其变得更好。即使您不熟悉编码或提交拉取请求(PR),您也可以通过提交带有错误的报告或请求新功能来支持它,或者简单地帮助讨论现有问题,以提供您的意见并塑造此包的进展。

联系方式

我非常愿意听到您的意见。我在 YouTube 上运营 dhamkith 频道,请订阅并查看视频。

您也可以通过 dhamkith@gmail.com 发送任何其他请求。