mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Add Contact model/view/controller
This commit is contained in:
parent
df772689be
commit
9de5f8bef3
4 changed files with 128 additions and 0 deletions
13
app/Contact.php
Normal file
13
app/Contact.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Contact extends Model
|
||||||
|
{
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
}
|
29
app/Http/Controllers/ContactController.php
Normal file
29
app/Http/Controllers/ContactController.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Auth;
|
||||||
|
|
||||||
|
class ContactController extends Controller
|
||||||
|
{
|
||||||
|
public function show(Request $request)
|
||||||
|
{
|
||||||
|
return view('site.contact');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
abort_if(!Auth::check(), 403);
|
||||||
|
|
||||||
|
$this->validate($request, [
|
||||||
|
'message' => 'required|string|min:5|max:500',
|
||||||
|
'request_response' => 'string|max:3'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$message = $request->input('message');
|
||||||
|
$request_response = $request->input('request_response') == 'on' ? true : false;
|
||||||
|
$user = Auth::user();
|
||||||
|
return $request->all();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateContactsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('contacts', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->bigInteger('user_id')->unsigned()->index();
|
||||||
|
$table->boolean('response_requested')->default(false);
|
||||||
|
$table->text('message');
|
||||||
|
$table->text('response');
|
||||||
|
$table->timestamp('read_at')->nullable();
|
||||||
|
$table->timestamp('responded_at')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('contacts');
|
||||||
|
}
|
||||||
|
}
|
49
resources/views/site/contact.blade.php
Normal file
49
resources/views/site/contact.blade.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
@extends('site.partial.template')
|
||||||
|
|
||||||
|
@section('section')
|
||||||
|
|
||||||
|
<div class="title">
|
||||||
|
<h3 class="font-weight-bold">Contact</h3>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<section>
|
||||||
|
@auth
|
||||||
|
<form method="POST">
|
||||||
|
@csrf
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="input1" class="font-weight-bold">Message</label>
|
||||||
|
<textarea class="form-control" id="input1" name="message" rows="6" placeholder=""></textarea>
|
||||||
|
<span class="form-text text-muted text-right msg-counter">0/500</span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-check">
|
||||||
|
<input type="checkbox" class="form-check-input" id="input2" name="request_response">
|
||||||
|
<label class="form-check-label" for="input2">Request response from admins</label>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary font-weight-bold py-0">Submit</button>
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
<p class="lead">
|
||||||
|
@if(filter_var(config('instance.email'), FILTER_VALIDATE_EMAIL) == true)
|
||||||
|
You can contact the admins by sending an email to {{config('instance.email')}}.
|
||||||
|
@else
|
||||||
|
The admins have not listed any public email. Please log in to send a message.
|
||||||
|
@endif
|
||||||
|
</p>
|
||||||
|
@endauth
|
||||||
|
</section>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@auth
|
||||||
|
@push('styles')
|
||||||
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||||
|
@endpush
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
<script type="text/javascript">
|
||||||
|
$('#input1').on('keyup change paste', function(el) {
|
||||||
|
let len = el.target.value.length;
|
||||||
|
$('.msg-counter').text(len + '/500');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
@endauth
|
Loading…
Reference in a new issue